Problems porting to linux. Video crashes
Lucas Dalmasso

Well, i tried to port my Allegro 5 app to linux and blum!! locked bitmaps pointers doesn't work.
Anyway they give me a negative pitch (stride).
And how do i put pixels to a 256*256 surface not using al_putpixel() which is slow?

Arthur Kalliokoski

You want al_put_pixel((int x, int y, ALLEGRO_COLOR color), not the al_putpixel() which is from allegro 4.

Lucas Dalmasso

Sorry i meant al_put_pixel(). The one in current Allegro 5.
I want to put the pixels locking and writing to the pointer, but it seems there is a problem in linux with that pointer.

Edgar Reynaldo

There's nothing wrong with the pointer. Pitch may be negative. You have to account for that.

Read over al_lock_bitmap and ALLEGRO_LOCKED_REGION.

The formula for pixel x,y is :

ALLEGRO_BITMAP* bmp = al_create_bitmap(480,360);
ALLEGRO_LOCKED_REGION* lock = al_lock_bitmap(bmp , ALLEGRO_LOCK_READWRITE , ALLEGRO_PIXEL_FORMAT_RGBA);

char* byte = lock->data + y*lock->pitch + 4*x + /*0,1,2,3*/;
al_unlock_bitmap(bmp);

Lucas Dalmasso

Ok, i have to fill all the screen starting from pixdel 0 to last pixel, so for the sake of doing it faster i only advance the pointer. Im not using X and Y coordinates (that's s why i wanted to do it that way), but it seems i cannot with a negative pitch.
When the same code runs in linux the system crashes and im using 256 width surface whichh is 256 * 4 = 1024 byes exactly of pitch.
It seems, indeed that OpenGL behaves differently than Direct3D in that matter.

Edgar Reynaldo

A multiply and an addition won't be significantly slower than just an increment, but it will be correct. And besides, that's the only correct way to do it.

EDIT
To be fair, you only need to reset the byte pointer when the line changes. You can still use increment along each line as you were before.

Thread #618495. Printed from Allegro.cc