Wide screen + Fullscreen + Allegro = ?
Albin Engström

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

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

Kibiz0r

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

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

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

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

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

Thanks :)

Kibiz0r
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

;D

Albin Engström

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

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

Richard Phipps

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

gnolam

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

spellcaster

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

William Labbett


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

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.

Kris Asick
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

Thomas Fjellstrom
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.

Runesabre

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.

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

weapon_S

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 :-[

Albin Engström

Seems like I'll have to scrap the widescreen+fullscreen support :/,
I can't think of a solution worth it's downside. :(

Kris Asick

Ok, here's a solution you'll like.

1. Ask the player the very first time they start your game whether they're using a standard or widescreen monitor. Store the answer into an options file.

2. When widescreen is selected, you can assume that the standard vertical will be present, such as 480, so just use get_gfx_mode_list() to get a list of valid display modes and choose whichever mode has the greatest X resolution with the Y resolution you desire.

3. Have an options screen where the user can switch between standard and widescreen. (Remember that you have to be running in SWITCH_BACKAMNESIA (fullscreen) or SWITCH_BACKGROUND (windowed) under Windows using set_display_switch_mode() before making additional calls to set_gfx_mode()... Or you just simply tell the user that changes will be applied when they restart the program.)

Simple enough, right? If the user doesn't understand that first question they probably aren't going to care if the game looks right or not.

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

Runesabre

That's effectively the solution I have come up with since I haven't found a programmatic way of detecting the monitor aspect yet.

My installer asks the player if they have a widescreen monitor. There's an option for "I don't know" at which point I then use get_resolution_depth() as a best guess.

Albin Engström

I just realized that 480/9 * 16 != valid resolution (853.480), it should be 848.480 :/.. no wonder it didn't work. but that means 16:9 is sort of a lie..

Kris Asick said:

When widescreen is selected, you can assume that the standard vertical will be present, such as 480, so just use get_gfx_mode_list() to get a list of valid display modes and choose whichever mode has the greatest X resolution with the Y resolution you desire.

but what happens if the greatest X resolution results in a wrong aspect ratio? because i take i that even resolutions that isn't suited for the monitor can still be used.

Thomas Harte
Quote:

so just use get_gfx_mode_list() to get a list of valid display modes and choose whichever mode has the greatest X resolution with the Y resolution you desire.

And remember that, per the docs:

Quote:

Note that the card parameter must refer to a real driver. This function fails if you pass GFX_SAFE, GFX_AUTODETECT, or any other "magic" driver.

So expect to have to write a fresh snippet of code for every platform you want to support, and add lots of #ifdefs and things like that. And don't expect your code to work correctly if anyone adds a new target to Allegro.

Allegro's rubbish like that.

Johan Halmén
Quote:

Running in 640x480 on a wide screen monitor results in pixels wider than high and it looks rather funny.

No problem. Check how people look at wide screen TV:s when the broadcasted image is 4:3. They stretch it and seem to have no problem with it. You may think it looks funny (I do!) but most people don't. They are so happy with their wide screen.

Albin Engström
Johan Halmén said:

No problem. Check how people look at wide screen TV:s when the broadcasted image is 4:3. They stretch it and seem to have no problem with it. You may think it looks funny (I do!) but most people don't. They are so happy with their wide screen.

Disgusting.

StevenVI

Do most widescreen TVs actually stretch like that? I have been graced with knowing someone so filthy rich as to have a very very large widescreen TV. For standard television shows it puts black bars on the left and right side of the screen, maintaining the aspect ratio. Perhaps it is just a top-of-the-line model?

Tobias Dammers
Quote:

Do most widescreen TVs actually stretch like that?

No. Each and every one I've seen so far has a menu option somewhere, where you can select what to do with 4:3 material: stretch, fit width (cutting off top and bottom), fit height (adding black bars). But each and every one I've seen so far also is set to "stretch mode" by default, probably because retarded people would complain about the black bars or the missing subtitles and operator logos otherwise. And people generally won't change it, either because they don't know they can, or because they're too lazy to care. It's still stupid.

Kibiz0r

Some have a fancy stretch option that stretches the edges more than the middle, so you get more square pixels in the middle and more rectangular ones near the edges. It actually looks quite nice unless there is a wide panning shot, because then the camera appears to be moving faster toward the edges.

spellcaster
Quote:

For standard television shows it puts black bars on the left and right side of the screen, maintaining the aspect ratio. Perhaps it is just a top-of-the-line model?

Normally that's one of the many options.
My TV allows me to stretch it, watch it in the normal aspect ratio and offers me 3 other zoom and/or stretching methods.

The TV also detects black bars at the top/bottom of the signal and automatically adjusts the stretched area. It's kinda nifty.

I normally don't bother and let the TV choose the best way to display the image. Most movies are broadcast with borders anyway, so the actual aspect ratio isn't that far from 16:9 anyway. And while I notice the remaining difference, I don' care much. A quizshow, the news or maybe a late night show don't really suffer if the aspect ratio isn't correct.

Karadoc ~~
Quote:

Some have a fancy stretch option that stretches the edges more than the middle, so you get more square pixels in the middle and more rectangular ones near the edges. It actually looks quite nice unless there is a wide panning shot, because then the camera appears to be moving faster toward the edges.

That actually a clever idea. I wonder if my TV can do that. :p

Albin Engström

Widescreen support implemented 8-). It ain't very good yet, but it's there.

Thanks a lot guys! I'll give credits when this thread dies.
btw: when checking "The question has been answered to my satisfaction!" is it possible to post in this thread afterwards?

Kibiz0r

Yes, but you have to post in order to do that, so how do you intend on doing that after the thread dies?

Albin Engström

I think i might be misunderstood.. oh well, nothing new :).

Kibiz0r

I kind of intentionally misunderstood you to poke a tiny amount of fun at the way you phrased it, just so I would have something to say other than "Yes." -- I am a sad, pathetic little man. Thanks for the cookies. 8-)

Albin Engström

^^'

Runesabre

I think I might have figured out a programmatic way to make an educated best guess of the true aspect ratio of the player's monitor.

I spent some time analyzing the results of get_gfx_mode_list() on both my development computer which has a 4:3 monitor and my laptop which has a 16:10 screen.

After getting the list, I examined all resolutions that were 32bpp and 800x600 or higher.

With this subset of modes, I tracked the number of 4:3, 16:9 and 16:10 resolutions supported. On my 4:3 monitor, there were more 4:3 resolutions supported. On my laptop, there were more 16:10 resolutions supported.

I also noted that the highest resolution available matched the true aspect of the monitor. It would make sense to me that the highest resolution of a given monitor matched it's true aspect ratio.

Of course, this could simply be a coincidence but I thought perhaps this might be useful.

ImLeftFooted

My solutions is to let people with widescreen crap get light warping glasses to play my game (aka say forget it :-/).

Monitors, if unable to actually support the modes they say they do, should have automagical scaling routines that make the pixels look right. And people should only buy those monitors because they are the only ones that make any kind of sense.

Sometimes capitalism drives me crazy...

Runesabre

I hear you, Dustin. The widescreen issue has been (surprisingly) one of my most frustrating issues developing my client. Not only the problem of not being able to succinctly detect the aspect ratio, but, other oddities like my laptop's lowest 16:10 resolution being 1280x800 whereas most machines support 960x600.

Albin Engström
Runesabre said:

With this subset of modes, I tracked the number of 4:3, 16:9 and 16:10 resolutions supported. On my 4:3 monitor, there were more 4:3 resolutions supported. On my laptop, there were more 16:10 resolutions supported.

I also noted that the highest resolution available matched the true aspect of the monitor. It would make sense to me that the highest resolution of a given monitor matched it's true aspect ratio.

Interesting, i hope more people will confirm this "coincidence".

Karadoc ~~

I'd be very surprised if anyone had an LCD monitor whose highest resolution did not match the aspect ratio of the monitor. But for CRT monitors, I wouldn't be as confident.

Oscar Giner

That doesn't work for CRT :P Mine is 4:3 and its maximum suported resolution is 1440x900, tough if I look at the highest heigh, the it's 1400x1050, which is 4:3

Trent Gamblin
Johan Halmén said:

No problem. Check how people look at wide screen TV:s when the broadcasted image is 4:3. They stretch it and seem to have no problem with it. You may think it looks funny (I do!) but most people don't. They are so happy with their wide screen.

My laptop is widescreen, and I have no problem with 4:3 aspect ratio. It looked a little funny at first, but I don't even notice it anymore.

Thread #592103. Printed from Allegro.cc