Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Wide screen + Fullscreen + Allegro = ?

Credits go to Kibiz0r, Kris Asick, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Wide screen + Fullscreen + Allegro = ?
Albin Engström
Member #8,110
December 2006
avatar

Running in 640x480 on a wide screen monitor results in pixels wider than high and it looks rather funny. But it's not funny anymore when you try to come up with a solution for the problem :(.

so my question is: How would you solve this problem?

William Labbett
Member #4,486
March 2004
avatar

Hey. I've had the same problem for ages but thought I couldn't explain it in words.
Thanks.

Kibiz0r
Member #6,203
September 2005
avatar

One solution would be to do it in widescreen mode, but still blit to the screen as if you were in 4:3, and center it so you get black bars to either side.

Albin Engström
Member #8,110
December 2006
avatar

Sounds like an idyllic solution, then how would i do this? I've been trying some things, but since they obviously doesn't work I'll have you answer my question :).

Thanks!

Kibiz0r
Member #6,203
September 2005
avatar

blit(buffer, screen, 0, 0, screen->w / 2 - buffer->w / 2, 0, buffer->w, buffer->h);

Completely untested. Might be slow, might have artifacts where the black bars should be.

William Labbett
Member #4,486
March 2004
avatar

widescreen is 16:9 so you can work out what to do from that..

Is there a way to detect a widescreen with allegro ?

Kibiz0r
Member #6,203
September 2005
avatar

get_desktop_resolution(int* width, int* height);
if (h * 4 == w * 3) //4:3 aspect ratio
else                //16:9 or 16:10

Albin Engström
Member #8,110
December 2006
avatar

I have a bad feeling about this.. although i shouldn't right?

Thanks :)

Kibiz0r
Member #6,203
September 2005
avatar

Quote:

I have a bad feeling about this.. although i shouldn't right?

Oh no, you definitely should.

Edit: This seems to work fine.

1#include <allegro.h>
2 
3int main()
4{
5 allegro_init();
6 install_keyboard();
7 set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1440, 900, 0, 0);
8 
9 //changed this line so you only have to change one line to change resolutions
10 BITMAP* buffer = create_bitmap((4 * SCREEN_H) / 3, SCREEN_H);
11 //if you want to not worry about what resolution you're in, use something OpenGL, or do a stretchblit instead of a blit
12 
13 while (!key[KEY_ESC])
14 {
15 clear_to_color(buffer, makecol(0, 0, 255));
16 circlefill(buffer, 100, 100, 20, makecol(0, 255, 0));
17 blit(buffer, screen, 0, 0, screen->w / 2 - buffer->w / 2, 0, buffer->w, buffer->h);
18 }
19}
20END_OF_MAIN()

Edit2: Changed a line for ease-of-use.

William Labbett
Member #4,486
March 2004
avatar

;D

Albin Engström
Member #8,110
December 2006
avatar

What do you think about: My game depends on the hight (it's a vertical shooter) which is 480, the ideal thing to do would be to only change the width. but as far as i can tell that's not possible. I can't find any good resolution to fit my game in widescreen, large resolution isn't an option as allegro is software rendered. :(.

Kibiz0r
Member #6,203
September 2005
avatar

Quote:

My game depends on the hight (it's a vertical shooter) which is 480, the ideal thing to do would be to only change the width.

Set up the buffer as normal then, and just do a stretchblit instead of a blit.

Quote:

allegro is software rendered.

Since it's a vertical shooter, I'll assume you're using draw_sprite instead of something like pivot_sprite. In which case, Allegro can be a hardware renderer. Just use video bitmaps instead of memory ones.

Albin Engström
Member #8,110
December 2006
avatar

Kibiz0r said:

Set up the buffer as normal then, and just do a stretchblit instead of a blit.

"normal"?? and what about triple buffering?

Kibiz0r said:

Since it's a vertical shooter, I'll assume you're using draw_sprite instead of something like pivot_sprite. In which case, Allegro can be a hardware renderer. Just use video bitmaps instead of memory ones.

Yes, i've heard about that, but never tried it. what about litting and transparent drawing?, if i lit a sprite from video memory to video memory, won't that require more power than from memory to video?.. or am i totaly lost? :)

Kibiz0r
Member #6,203
September 2005
avatar

Quote:

if i lit a sprite from video memory to video memory, won't that require more power than from memory to video?

I think so, but don't hold me to that.

Quote:

"normal"?? and what about triple buffering?

Normal: create_bitmap(640, 480)

Triple buffering: Would be if you were using video memory.

Kris Asick
Member #1,424
July 2001

Here's a neat trick. Most widescreen monitors support standard vertical resolutions, so when running full-screen just start with 960x480 or something ridiculous and just keep scaling the first number back until set_gfx_mode() finally succeeds. ;)

For example:

for (z = 960; z >= 640; z--)
  if (!set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,z,480,0,0)) break;

if (screen == NULL) { /* Unable to set any graphics mode */ }

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Richard Phipps
Member #1,632
November 2001
avatar

Won't that cause flickering and slow-down as the monitor attempts to open a non-existant mode?

gnolam
Member #2,030
March 2002
avatar

Kris: That's a horrible idea, and you should be subjected to a public beating for even suggesting it. Have you any idea of what that kind of resolution setting abuse would do to my poor monitor? :P

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

spellcaster
Member #1,493
September 2001
avatar

Well, you could also check the list of available modes reported by allegro ;)
Using the desktop resolution is a more easy way, though.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

William Labbett
Member #4,486
March 2004
avatar


The other problem with having a widescreen is that although you can get round it with allegro when you're running a creative program like a graphics editor for example what do you do then ? Making graphics like this doesn't seem an optimal way (having to imagine what they'd look like in different proportions).

Tobias Dammers
Member #2,604
August 2002
avatar

Graphics editors are generally windowed applications, and as such, will automatically use the desktop resolution. If the user has set it to something sensible (read: a widescreen resolution), then pixels are still square and everything looks fine. You just have a wider working area.

Widescreen only causes trouble when you decide to override the desktop resolution and set a different one.

BTW, I think widescreens are the most stupid invention ever made. I use my computer for editing all sorts documents, and 95% of these have one thing in common: they are taller than wide, so the closer the aspect ratio comes to 1 : sqrt(2), the happier I am.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Kris Asick
Member #1,424
July 2001

Quote:

Won't that cause flickering and slow-down as the monitor attempts to open a non-existant mode?

Quote:

Kris: That's a horrible idea, and you should be subjected to a public beating for even suggesting it. Have you any idea of what that kind of resolution setting abuse would do to my poor monitor?

Just so you know, if you attempt to set a mode which isn't valid, absolutely nothing happens. No switching, no delays, nothing. If a full-screen mode doesn't exist, there's no way for the monitor to actually switch into anything. The monitor driver knows what's valid and what isn't. So short of checking the list Allegro stores internally, that's the simplest method to autodetect a widescreen resolution, since an actual switch will not occur until a valid mode combination of X and Y resolution is chosen. It is a very horrible idea if you're running windowed though! ;)

Ok, I tested that code just to see for myself what would happen. Yes, there was flickering for half a minute as the Allegro window appeared and disappeared rapidly, but short of that it worked. So it does work, it's just not practical. ::)

However, using any autodetect method for widescreen by default is bad because many non-widescreen monitors can actually display widescreen resolutions. So it's good to ask a user on first run of a program, or as suggested, to figure out if the desktop res is a wide-screen resolution or not.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

If a full-screen mode doesn't exist, there's no way for the monitor to actually switch into anything. The monitor driver knows what's valid and what isn't

Heh. You'd like to think so. But many monitors report incorrect modes and resolutions, and miss some valid ones, etc. And yes, you can set invalid modes for monitors, then they go into "sleep" mode with a message saying "you fucked up". Or even worse, some will display some weird ass shit till the mode is changed back.

Quote:

However, using any autodetect method for widescreen by default is bad because many non-widescreen monitors can actually display widescreen resolutions.

Sure, but the monitors aspect ratio is still 4:3, which means that widescreen res is squished quite a bit.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Runesabre
Member #7,573
August 2006
avatar

Is there a way to programmatically determine the aspect ratio of the monitor? get_desktop_resolution() relies on the player having set a proper resolution.

_______________
Runesabre
Connecting People through Inspiring Interactive Entertainment
Enspira Online

StevenVI
Member #562
July 2000
avatar

Quote:

get_desktop_resolution() relies on the player having set a proper resolution.

If the user can't set a proportional resolution on their computer then they probably won't realize that the game they're playing looks like poo.

My girlfriend's laptop is widescreen and I was programming on it the other night when I noticed the neat effect of which this thread is about. It didn't hinder gameplay, just made things look kinda funny.

I say this as a backup to my argument. The user who's resolution is improperly set is probably already aware that their computer is retarded and have submitted to their fate of everything stretched.

__________________________________________________
Skoobalon Software
[ Lander! v2.5 ] [ Zonic the Hog v1.1 ] [ Raid 2 v1.0 ]

weapon_S
Member #7,859
October 2006
avatar

Actually I once did the opposite: set an widescreen resolution on a normal monitor.
I have this ancient MIDI sequencing program, which can display more depending on the horizontal pixel resolution. And I wanted the overview for a particular music.
So maybe they're not retarded: people who incorrectly set their resolution >:(
Look at my self Maybe they are :-[

 1   2 


Go to: