Programming Random Memo
Most Popular
PNG Encoder and Decoder in C++
Minimalists' OpenGL Application Framework for Windows, Mac OSX, and Linux
Adding Printf-able Console Window to MFC application.
Sample codes for generating bitmap images from a UNICODE string for Windows, Mac OSX, and Linux (Plus UTF8 <-> WChar conversion functions)
Joystick-reading function and Joystick calibrator
Strange linker error when compiling 64-bit Mac OS X binary and solution.
C++ example for playing WAV file with Pulse-Audio API in Ubuntu 11.1

07/11/2014

Cross-Compiling 32-bit OpenGL program in 64-bit Ubuntu

Until now, I was compiling 32-bit binary on 32-bit Ubuntu, and 64-bit binary on 64-bit Ubuntu.  I launch a different virtual machine in VirtualBox for each case.  But, it's not very efficient.  It is the same operating system.  I have been wanting to build and package both 32-bit and 64-bit version binary from one script.

There are options -m32 and -m64 of gcc, which force the compiler to spit out 32-bit and 64-bit binary respectively.  However, if I tried gcc -m32 in 64-bit Ubuntu, I was getting an error complaining predef.h not found.  Today, somehow that problem came back to my mind.  I searched for the solution and learned that what I needed was multilib libraries.

Further search indicated that not all libraries are as convenient as multilib, but I can do  sudo apt-get install lib???:i386 to get 32-bit version libraries in most cases.  That made me hopeful.  I thought it should be easy to set up cross-compiling so that I can compile both 32-bit and 64-bit binaries in 64-bit Ubuntu.

Then I hit a brick wall.  After installing multilib, gcc told me that libGL and libGLU cannot be found.  Not a big deal.  I should be able to apt-get install libgl1-mesa-dev:i386 and libglu1-mesa-dev:i386 to install 32-bit version of libGL and libGLU, right?  Unfortunately it turned out not so easy.  apt-get gave me an error and could not install 32-bit libGL and libGLU.  Search implied that it is one of the known bugs of Ubuntu (or Debian).

(Read more)

06/25/2014

PNG Decoder

Support 4-bit Indexed Color.

[Download from here]

03/22/2014

The best alternative solution for making constant inheritance (or read-only inheritance or you call whatever you want) in C++ that I came up with so far.

In this page, I am posting the best solution toward constant inheritance in C++ that I came up with so far.  I believe many people are trying but failing to make a const inheritance in C++.  I think some call it read-only inheritance.  You can call it whatever you want.  I'm calling it const inheritance.  I spent good amount of time searching for a solution, but I couldn't find a good solution.

What I want to do is this:

class YsShell
{
public:
    // Something useful
};

class YsShellExt : private YsShell
{
public:
    operator const YsShell &() const;
};

YsShellExt is privately derived from YsShell.  So, I want to mostly prohibit access to YsShell through YsShellExt.  But, I want to open constant access to YsShell by the conversion operator.

However, C++ specification apparently doesn't allow you to do it. (Read full text)

PNG Encoder and Decoder in C++

Bug fix based on the user's feedback.  I was not populating sliding-window while decoding an uncompressed block.  Thank you for the report!

It adds a PNG decoding capability to the program just by adding yspng.cpp and yspng.h to the project.  Since I wrote from the scratch only looking at the PNG & LZ77 specification, there is absolutely no GPL trap.  It does NOT require "XX library of YY version and UU library of VV version" kind of, therefore you are free from the maintenance nightmare.  I have been using this decoder for years, and apparently is used over the world, therefore the code has been well trained and stable by now.  This PNG decoder was at the top of Google result for "C++ PNG decoder" until recently, but as I checked now, it was shown at the 2nd place :-P

[Download from here]

(Old Topics) Close Encounter of the Mac Programming (How I am learning Mac OS X programming)