Links
Tags
apache
armenia
books
bsd
c
c++
chips
cinema
concurrency
cooking
database
dragonfly
erlang
filesystem
freebsd
fun
hardware
java
javascript
json
languages
linux
lyric
mac_osx
mail
math
misc
music
personal
poems
presentation
programming
python
references
ruby
rubyjs
scm
software
spiking_neural_net
study
sysadm
sysarch
technology
testing
travel
virtualization
web
wee
windows
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!