Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » OpenGL clipping on sub bitmaps

This thread is locked; no one can reply to it. rss feed Print
OpenGL clipping on sub bitmaps
Matthew Leverton
Supreme Loser
January 1999
avatar

Perhaps related to this thread. It doesn't look like OpenGL honors clipping on sub bitmaps. Test program:

#SelectExpand
1int main() 2{ 3 al_init(); 4 al_init_primitives_addon(); 5 al_set_new_display_flags(ALLEGRO_OPENGL); 6 7 ALLEGRO_DISPLAY *display = al_create_display(320, 240); 8 ALLEGRO_BITMAP *sub = al_create_sub_bitmap(al_get_backbuffer(display), 0, 0, 320, 240); 9 10 // clear to black 11 al_set_target_bitmap(sub); 12 al_clear_to_color(al_map_rgb(0,0,0)); 13 14 // 64x64 clip with filled white rectangle 15 al_set_clipping_rectangle(0, 0, 64, 64); 16 al_draw_filled_rectangle(0, 0, 320, 240, al_map_rgb_f(1,1,1)); 17 18 al_flip_display(); 19 20 al_rest(5); 21 return 0; 22}

My initial test was clipping a sub bitmap of a regular (non backbuffer) bitmap; it had the same problem.

Expected result (D3D):

{"name":"602854","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/d\/7d70960c3c746fc2e5e21cbe8ad29116.png","w":336,"h":278,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/d\/7d70960c3c746fc2e5e21cbe8ad29116"}602854

OpenGL:

{"name":"602855","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5ee6bba9dd6ca61d2d6945ec46283bb2.png","w":336,"h":278,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5ee6bba9dd6ca61d2d6945ec46283bb2"}602855

It works fine when the sub bitmap is removed.

Elias
Member #358
May 2000

Can you try adding this to ogl_update_clipping_rectangle (in src/opengl/ogl_bitmap.c):

if (bitmap->parent) ogl_bitmap = bitmap->parent;

Basically the check if the bitmap is the opengl_target looks wrong to me as it would fail for sub-bitmaps. Can't test it myself right now.

--
"Either help out or stop whining" - Evert

Matthew Leverton
Supreme Loser
January 1999
avatar

The attached patch seems to work.

Index: ogl_bitmap.c
===================================================================
--- ogl_bitmap.c	(revision 14083)
+++ ogl_bitmap.c	(working copy)
@@ -530,6 +530,10 @@
    ALLEGRO_DISPLAY *ogl_disp = al_get_current_display();
    ALLEGRO_BITMAP_OGL *ogl_bitmap = (void *)bitmap;
 
+   if (bitmap->parent) {
+      ogl_bitmap = (ALLEGRO_BITMAP_OGL *)bitmap->parent;
+   }
+
    if (ogl_disp->ogl_extras->opengl_target == ogl_bitmap) {
       _al_ogl_setup_bitmap_clipping(bitmap);
    }

Go to: