[A5] shouldn't al_set_clipping_rectangle use floats?
axilmar

The function al_set_clipping_rectangle uses integers, however the drawing functions take floats as arguments.

Matthew Leverton said in another thread that someone might setup the screen to go from (0,0)-(1,1).

If someone does that, then what values should be passed to al_set_clipping_rectangle?

Arthur Kalliokoski

I'd imagine the function uses the reciprocal of the bitmap size.

Elias

I'd imagine the function uses the reciprocal of the bitmap size.

Indeed. With bitmap being whatever is returned by al_get_target_bitmap. We only support aligned clipping rectangles, so using the transformations doesn't make sense (e.g. what if someone use a transformation to rotate by 45 degree).

axilmar

So when one uses clipping, the screen coordinate system must not be transformed to (0,0)-(1,1)?

Arthur Kalliokoski

Use the prototype, Luke!

[EDIT]

Trust them. Seriously. If it doesn't work, then post questions.

Todd Cope

Transformations do not affect the result of al_set_clipping_rectangle(). You can use transformations with clipping just remember that you will need to convert your clipping coordinates to "pixel" coordinates to use with al_set_clipping_rectangle().

SiegeLord

There's some confusion here.

al_set_clipping_rectangle() sets the clipping rectangle of the target bitmap's pixels.

"Setting up a screen to go from (0,0)-(1,1)" means that you'll create a transformation which maps input coordinates (like those you pass to al_draw_bitmap) ranging from (0,0)-(1,1) to what the target bitmap's dimensions are (e.g. (0,0)-(800,600)).

So, to clip coordinates (0,0)-(0.5,0.5) you'd do:

al_set_clipping_rectangle(0, 0, al_get_bitmap_width(al_get_target_bitmap()) * 0.5, al_get_bitmap_height(al_get_target_bitmap()) * 0.5);

In other words, the clipping rectangle is applied only after all the transformations have been applied, not before.

Matthew Leverton

I was speaking of setting up a transformation on the back buffer such that a blit or primitive operation call to it would transformed. That would obviously affect your GUI's drawing operations.

Things like the mouse will always be reported in integer screen x,y positions, etc. Clipping is always done in actual bitmap coordinates as well. So for your usage, I don't see how supporting such transformations would be practical.

Mark Oates

Eventually, it may be a good idea to support draw_with_alpha routines.

Elias

Eventually, it may be a good idea to support draw_with_alpha routines.

What would those do?

axilmar

Ok, thank you guys. My gui uses clipping to limit widget output, and since mouse coordinates are integers, I will stick to integer coordinates in my gui. This means that if a game uses my gui and does transformations on the coordinate system, there is going to be a problem, but I don't see a good solution to this.

Todd Cope

You could use the state API (al_store_state(), al_restore_state()) to store the user's transformation and use the identity transformation when rendering your GUI. This way your GUI will always render correctly and the user's coordinate system will be restored and ready for them to use when your done.

Matthew Leverton

Right, but the programmer wouldn't be able to do something like:

resize_widget(0.5, 0.5);

But to me, that's not a big deal, because it really doesn't make much sense if you know what transformations are with respect to Allegro.

Edgar Reynaldo

There's nothing stopping you from doing

gui_resize_widget_f(gui* g , widget* w , float w_percent , float h_percent);

is there?

The gui knows its dimensions, and applies the percentage to a secondary resize widget function call.

Mark Oates
Elias said:

What would those do

I'm thinking of functions that draw anything to a bitmap, but only through an alpha mask (or just a grayscale bitmap.)

As it is now, the effect can be done with offscreen renders and changing to alpha-only blending modes, but it seems like there would be a more proper low-level way to do it. OpenLayer had this feature, if I recall correctly.

It's a feature I'll surely advocate for more in the future, when I get around to it. ;) That and primitive drawing with filtering to off-screen bitmaps. With those two you could then combine them to get the equivalent of a sub-pixel clipping region, or any clipping shape for that matter.

[edit]I'm thinking of something as simple as

al_set_alpha_mask(ALLEGRO_BITMAP *b);
al_unset_alpha_mask();

and any subsequent drawing operations would only draw the pixels through that mask.

axilmar
Todd Cope said:

You could use the state API (al_store_state(), al_restore_state()) to store the user's transformation and use the identity transformation when rendering your GUI. This way your GUI will always render correctly and the user's coordinate system will be restored and ready for them to use when your done.

Thanks, that's what I'm gonna do.

But to me, that's not a big deal, because it really doesn't make much sense if you know what transformations are with respect to Allegro.

I agree.

The gui knows its dimensions, and applies the percentage to a secondary resize widget function call.

The problem is the sub-pixel clipping, not the widget resizing.

Elias

al_set_alpha_mask(ALLEGRO_BITMAP *b);
al_unset_alpha_mask();

Setting it to NULL could naturally do the unset so the extra unset function is probably not necessary.

And maybe we should call it al_set_stencil_mask to make more clear what it would do.

Also, I was thinking about something like:

al_set_stencil_target(display);

Which would allow drawing directly to the stencil buffer.

The software renderer likely would not support this at all, or else it just would be an extra if() in the draw_pixel function.

Thread #606562. Printed from Allegro.cc