Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] shouldn't al_set_clipping_rectangle use floats?

Credits go to Matthew Leverton and Todd Cope for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] shouldn't al_set_clipping_rectangle use floats?
axilmar
Member #1,204
April 2001

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
Second in Command
February 2005
avatar

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

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Elias
Member #358
May 2000

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).

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

axilmar
Member #1,204
April 2001

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

Arthur Kalliokoski
Second in Command
February 2005
avatar

Use the prototype, Luke!

[EDIT]

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

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Todd Cope
Member #998
November 2000
avatar

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
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Matthew Leverton
Supreme Loser
January 1999
avatar

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
Member #1,146
March 2001
avatar

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

Elias
Member #358
May 2000

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

What would those do?

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

axilmar
Member #1,204
April 2001

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
Member #998
November 2000
avatar

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
Supreme Loser
January 1999
avatar

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
Member #8,592
May 2007
avatar

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
Member #1,146
March 2001
avatar

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
Member #1,204
April 2001

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
Member #358
May 2000

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.

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

Go to: