Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [a5] best way to scale/stretch screen?

This thread is locked; no one can reply to it. rss feed Print
[a5] best way to scale/stretch screen?
Aaron Santiago
Member #12,074
June 2010
avatar

I'm creating a game where I'm going in the direction of hardcore pixel art. I might even go as far as to run the game in less than 100 * 100 resolution. The thing is, I still want people to make things out on the screen. :P
As far as my newly discovered a5 skills go, I have two options:
- Use a separate buffer and scale/stretch it when blitting to the Allegro backbuffer
- Find the screen resolution before the game starts, and scale every bitmap and every number accordingly.
I'm scared of the first one because of the anticipated speed hit, since: 1) It's scale/stretching a huge bitmap the entire time, and 2) It's slower drawing things with alpha to memory bitmaps than it is to the backbuffer. I'm scared of the second one because it would require me to use nothing but floats (which in itself makes me cringe) and just sounds like bug city.
Is there a magical third option I don't know about, or is there a better way to do either of the above? ???

Matthew Leverton
Supreme Loser
January 1999
avatar

There are two main things, which you've outlined:

  1. use a small buffer and scale only the final blit

  2. use a full screen buffer and scale every call

The first is better for bitmap oriented games. The second is better if you are drawing everything with primitives, because you'll get higher resolution.

You can do the latter via the transformation API. Just use (0,0)-(1,1) in your code and set up a transformation that scales by (w,h).

Trent Gamblin
Member #261
April 2000
avatar

Aaron Santiago
Member #12,074
June 2010
avatar

#SelectExpand
1float scaleX = al_get_display_width(currentDisplay)/currentResW; 2float scaleY = al_get_display_height(currentDisplay)/currentResH; 3ALLEGRO_TRANSFORM trans; 4al_scale_transform(trans, scaleX, scaleY); 5al_use_transform(trans); 6//draw as normal?

I'm hoping that's it? Most of what I read in the docs went straight over my head.

Trent Gamblin
Member #261
April 2000
avatar

That's pretty much it, but watch the integer math in those divisions. You could end up with some non-exact fitting images.

Matthew Leverton
Supreme Loser
January 1999
avatar

float scaleX = al_get_display_width(currentDisplay)/(float)currentResW;
float scaleY = al_get_display_height(currentDisplay)/(float)currentResH;
ALLEGRO_TRANSFORM trans;
al_identity_transform(&trans);
al_scale_transform(&trans, scaleX, scaleY);
al_use_transform(&trans);

Aaron Santiago
Member #12,074
June 2010
avatar

That's pretty much it, but watch the integer math in those divisions. You could end up with some non-exact fitting images.

You, uh, you lost me there. Does that mean it's better to do:

#SelectExpand
1float screenWidth = al_get_display_width(currentDisplay); 2float screenHeight = al_get_display_height(currentDisplay); 3float floatResW = currentResW; 4float floatResH = currentResH; 5float scaleX = screenWidth/floatResW; 6float scaleY = screenHeight/floatResH; 7ALLEGRO_TRANSFORM trans; 8al_scale_transform(trans, scaleX, scaleY);

?
Because if so, then I learned something (else) new today.

Matthew Leverton
Supreme Loser
January 1999
avatar

I assume you also need to initialize it to the identity first. See my previous post.

Trent Gamblin
Member #261
April 2000
avatar

Yeah Matthew nailed it.

Aaron Santiago
Member #12,074
June 2010
avatar

I assume you also need to initialize it to the identity first. See my previous post.

Whoa, yeah, that. I also didn't notice that I shouldn't be passing trans directly, thanks.

#SelectExpand
1float scaleX = al_get_display_width(currentDisplay)/(float)currentResW; 2float scaleY = al_get_display_height(currentDisplay)/(float)currentResH;

Matthew Leverton said:

(float)currentResH;

Matthew Leverton said:

(float)

-.- duh. Thanks a ton. ;D

Matthew Leverton
Supreme Loser
January 1999
avatar

FYI, the attributes to the <quote> and <code> tags are optional and usually not necessary.

Aaron Santiago
Member #12,074
June 2010
avatar

<quote name="Matthew Leverton">FYI, the attributes to the

and <code> tags are optional and usually not necessary.

Oh, I know. I'm just super OCD and stuff.

[edit]
iseewhatyoudidthere.jpg
-_-

Go to: