open GL + al_draw_indexed_prim
duncan perham

I have been working on bringing spine animations into my game, however, having just spent a week getting it all working, when I merged it into my game I've hit a serious problem.

It draws the graphics using al_draw_indexed_prim, which it seems needs ALLEGRO_OPENGL as a display flag. which if I set that it works fine, however, when I use ALLEGRO_OPENGL as a display flag it causes my graphics loader to crash.

ALLEGRO_LOCKED_REGION* lock = al_lock_bitmap(bmp,ALLEGRO_PIXEL_FORMAT_RGBA_8888 , ALLEGRO_LOCK_WRITEONLY);
memcpy(lock->data,Buffer,(4*Width)*Height);
al_unlock_bitmap(bmp);

So im between a rock and a hard place here, al_draw_indexed_prim does not work if openGl is not used, but if I use OpenGL, something happens to the memcopy function that causes a crash.

Is there another al_draw_indexed_prim that will work without GL.
Or does anyone know why the memcopy is crashing? (works 100% without openGL).

As a side note, when I set al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); it all worked OK, but was 1000X slower. ????

Elias

You need to use lock->pitch (which is usually negative with OpenGL). So something like:

ALLEGRO_LOCKED_REGION* lock = al_lock_bitmap(bmp,ALLEGRO_PIXEL_FORMAT_RGBA_8888 , ALLEGRO_LOCK_WRITEONLY);
for (int i = 0; i < Height; i++) {
    memcpy((uint8_t)lock->data + i * lock->pitch, Buffer + i * 4 * Width, 4*Width);
}
al_unlock_bitmap(bmp);

duncan perham

Thanks a million, that all works well together now :).

Thread #615834. Printed from Allegro.cc