20. May, 2003
20. May, 2003
in by Michael Neumann
After finishing my Julia set program (Tech/ComputerScience/JuliaSets), I decided to make a fractal zoomer. But now, PNM files are no more sufficient, what I really need is a graphics library.

But, which graphics library should I use?

I am not looking for a graphics library that rules the world. All I want is to draw directly into the frame-buffer. In the good ol’ DOS days, it was so simple. Two assembler commands to switch into mode 13h (320x200x8):

mov ax, 13h
int 10h

Then I was able to write directly into the frame-buffer (I believe the memory location was 0xa000).

I started with evaluating libGGI, as it’s very portable. But after I was ready with the program, I realized that the pixel routine was too slow. So I tried Clanlib, but it failed to compile on FreeBSD. I though, ok, let’s try libSDL. I read some docs about SDL, but the pixel routine in the tutorial tried to handle all possible color depths. Then I tried Allegro. I used it in the past (yeah, good ol’ DOS days), and found it very pragmatic, not trying to abstract every piece of my hardware.

Allegro

Wow, I hacked up my first little program in 5 minutes. It really looks like programming in DOS. Everything is so simple.

if (allegro_init() != 0)
{
  // fail
}

install_keyboard();
set_color_depth(32);

if (set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
  // fail
}

acquire_screen();

// ... draw on screen

release_screen();

readkey();

It is easy to create a bitmap (for double buffering), write directly into it, and copy it to screen:

BITMAP *bmp = create_bitmap(800, 600);

for (int row=0; row<600; row++) {
  for (int col=0; col<800; col++) {
    ((unsigned int*)bmp->line[row])[col] = makecol(255,0,0); // fill red
  }
}

blit(bmp, screen, 0, 0, 0, 0, 800, 600);

And peng, it’s displayed on the screen, without delay! That’s all I need for my fractal zoomer. Great!