Sign in to follow this  

Handling Resolution in a 2D OpenGL/GLUT game

This topic is 2657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, so far I've successfully stumbled through the process of loading and applying textures to quads, complete with alpha. (I know I should probably be using triangles instead of quads, but I'll be able to figure that out myself in short order, I'm sure)

Now, I'm wondering what I should do with the resolution, and I figured I'd ask about it because there seems to be a large number of options and concerns and I'm not terribly experienced with OpenGL. What I'm imagining (sorry if I don't quite use the proper terminology) is a full screen 2D game in which the space that the game should take place is a square. Rather than stretching the square (and the game's graphics) upon full screening I'd rather just deal with the extra space of wider screens by adding black bars on the sides, leaving the graphics unstretched. I'm not sure how to go about this exactly.

Furthermore, I'd like to enforce a particular resolution. While I figure the commands to do that aren't hard and the most complex thing I'd have to do is pick a proper resolution based on the screen aspect ratio, I thought I would ask if there's any handy tips or things to consider on that subject.

Not sure if this is too advanced for the beginner's section or what. But I definitely feel like a beginner. Also, I did some searching on google and in these forums, but haven't found anything with enough of a concise explanation for my purposes. Sorry if I'm asking any common questions, because I didn't see any obvious answers.

Thanks ahead of time.

Share this post


Link to post
Share on other sites
I think the main thing you'll want to consider is whether or not you need 'pixel-perfect' graphics. If not, the solution is fairly straightforward; otherwise, it's a little less so.

If you don't need pixel-perfect graphics, then the solution is to run your game at a fixed 'virtual resolution' that's independent of the screen resolution. This way, everything can be handled internally in the same way regardless of screen resolution.

You'll still have to handle differing aspect ratios, but this isn't too hard. Basically, what you need to do is find the 'best fit' for a square (or whatever shape your play area is) with respect to the screen. For aspect ratios > 1 (which is the more typical case), you would fit the play area exactly to the screen's vertical size, and then leave the 'extra space' on the left and right sides blank (or fill them with decorative graphics or whatever).

If you need pixel-perfect graphics, you have a couple of options:

1. Enforce a fixed resolution. As I understand it at least, this isn't a particularly viable option these days due to the wide range of hardware and due to the fact that even for hardware that (technically) can run the requested resolution, the image quality may be poor if the resolution is not the hardware's native resolution.

2. Render pixel-for-pixel regardless of what resolution the user selects. This means the hardware needs to support *at least* the resolution in question, and also that your game will appear smaller onscreen as the screen resolution increases.

Anyway, that's my understanding of it at least. (Maybe there are other options, but they're not coming to mind at the moment.)

Share this post


Link to post
Share on other sites
I actually didn't say anything about it, but I was thinking it: I DO want pixel-perfect. This game will be entirely pixel art, and I don't want it messed up. I was actually concerned about that, since even full-screening at my screens exact current resolution resulted in awkward looking texels.

I figured enforcing a resolution wouldn't be too bad, considering that I've seen other games do it. But I agree that that could wind up being wiggy on particular systems. But if I have no other option...

Is there a particular way to set up the view port "zoom level" to achieve one-for-one texels to pixels? I'm not sure how I would calculate that.

Edit: nevermind, searching "pixel perfect" on google seems to be getting me some info.

Share this post


Link to post
Share on other sites
Quote:
Original post by Darlos9D
I figured enforcing a resolution wouldn't be too bad, considering that I've seen other games do it.
The impression I get is that that option is less viable now than in the past, even the fairly recent past. Yeah, I've also seen some fairly recent (and successful) games that used a fixed resolution, but I think they may sort of represent the tail end of that trend.

I could be wrong, but my understanding is that on some monitors, using resolutions other than the native resolution can lead to substandard image quality. (This is just what I've read - I haven't run into it myself.) There's also the issue of aspect ratio to deal with; you can't just require, say, 800x600, because then you'll either end up with distorted graphics (potentially) or lock out users with non-4:3 monitors. You can require a fixed height and still get pixel-perfect graphics that way, but you may not be guaranteed of getting a suitable resolution on a particular hardware configuration.

You'll also need to consider that the user may want to run your application in windowed mode, in which case the apparent size of your graphics will be dependent on the desktop resolution anyway.

Anyway, I may be overlooking something here, but the impression I've gotten is that using a fixed resolution can be problematic given the wide variety of hardware configurations currently available. Maybe someone else will offer a different view though.

Share this post


Link to post
Share on other sites
Well, I've seen successful 2D games that seem to completely disallow windowed mode. Though I suppose that does present a lack of options, though why somebody would be multi-tasking on their computer while playing a high-speed intense space shooter, I have no idea.

It seems like it'd be nice if there was some way to find out what ALL of the available resolutions are, and then dynamically pick the closest one I need and apply black borders as necessary. I'll google that and see what I find.

EDIT: I've been having some success. I can use EnumDisplaySettings() in order to not only discover the current display settings, but also all available display settings of the main display device. Then, I'm in a lot of luck, because I don't actually have to go manually changing the resolution. GLUT comes with a concept called "game mode." Rather than using regular window creation, you first use glutGameModeString() to input a string that describes your desired resolution and refresh rate. Then you use glutEnterGameMode(), which automatically fullscreens your app in the desired resolution. I'm not sure if it actually changes the system resolution or just does some kind of simulated resolution, but it seems to do the trick. Plus from what I read it's more efficient than other more roundabout methods.

So, I just find the closest resolution to my desired game dimensions that matches the device aspect ratio (which I assume is just the aspect ratio of the current resolution, which seems like a safe bet), and then add a black border to cover the excess horizontal and vertical space, as well as some "offsets" to keep all my drawing in the center of the screen. Seems to work pretty well!

The only problem is that the pixels still seem a tad wiggy. I'm willing to allow that to slide to some degree, but I'd like to minimize the problem as much as possible. I've read around that I need to offset some of the graphics by 0.5 pixels or something, though I'm not certain I fully understand. I just can't seem to get the texels lined up with the pixels perfectly. I'm starting to get a bad feeling from reading around the internet that I might be kinda screwed in that department, which is rather disappointing...

[Edited by - Darlos9D on September 3, 2010 10:50:52 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Darlos9D
Well, I've seen successful 2D games that seem to completely disallow windowed mode. Though I suppose that does present a lack of options, though why somebody would be multi-tasking on their computer while playing a high-speed intense space shooter, I have no idea.
I think some people like to be able to switch to other applications easily, even when playing action-oriented games. I think the bigger question though is whether you (the general you) should limit the player's options based on what you yourself would or would not want to do.

Again, I could be wrong, but I'm not sure that disallowing windowed mode would be the best solution.
Quote:
It seems like it'd be nice if there was some way to find out what ALL of the available resolutions are, and then dynamically pick the closest one I need and apply black borders as necessary. I'll google that and see what I find.
Keep in mind that on monitors with a native resolution, it still may be possible to pick other resolutions at which your game may not look as good. (Again, this is from what I've read - I haven't actually run into this myself.)
Quote:
The only problem is that the pixels still seem a tad wiggy. I'm willing to allow that to slide to some degree, but I'd like to minimize the problem as much as possible. I've read around that I need to offset some of the graphics by 0.5 pixels or something, though I'm not certain I fully understand. I just can't seem to get the texels lined up with the pixels perfectly. I'm starting to get a bad feeling from reading around the internet that I might be kinda screwed in that department, which is rather disappointing...
I've never tried to do pixel-perfect graphics in OpenGL, so I can't comment directly on this. I've read about the pixel offset thing, but it does seem a bit fiddly, and I think maybe I remember reading that the behavior can't be counted on to be entirely consistent across implementations. (I may be misremembering that though.)

Share this post


Link to post
Share on other sites
Quote:
Original post by jykI think some people like to be able to switch to other applications easily, even when playing action-oriented games. I think the bigger question though is whether you (the general you) should limit the player's options based on what you yourself would or would not want to do.

Again, I could be wrong, but I'm not sure that disallowing windowed mode would be the best solution.

Well, there's always alt-tab. Honestly I think people can deal.

Quote:
Original post by jykKeep in mind that on monitors with a native resolution, it still may be possible to pick other resolutions at which your game may not look as good. (Again, this is from what I've read - I haven't actually run into this myself.)

I've alleviated this problem (I think) by checking the aspect ratio of the current resolution before starting the game. Then I only choose a new resolution with the same aspect ratio (because indeed, monitors seem to support resolutions that don't fit the screen). Seems to work. Of course, this could be messed up if the user is for some reason using a resolution with an aspect ratio that doesn't match their monitor shape, but I'm not sure why anyone would do that.

Quote:
Original post by jykI've never tried to do pixel-perfect graphics in OpenGL, so I can't comment directly on this. I've read about the pixel offset thing, but it does seem a bit fiddly, and I think maybe I remember reading that the behavior can't be counted on to be entirely consistent across implementations. (I may be misremembering that though.)

Yeah, that's pretty much what I've read unfortunately. What a mess...

Share this post


Link to post
Share on other sites
Quote:
Well, there's always alt-tab. Honestly I think people can deal.
My experience is that alt-tabbing from fullscreen is not as responsive, user-experience wise, than alt-tabbing between windowed applications.

This is just my own view based on what I've seen and read online, but IMO, 'I think people can deal' may not be the best approach to take to application design. In some cases at least, people may find it frustrating if an application takes control out of their hands, doesn't offer the basic features they're used to having available, or otherwise doesn't play nice with the user's environment.

Granted, lots of games historically have done things like this (fullscreen only, disabling alt-tab and other keyboard shortcuts, etc.), but I think with multitasking becoming increasingly common, users may find this less acceptable now than in the past.

But, that's just my view on things, and is mostly due to anecdotal stuff that I've picked up online. Anyway, if going exclusively fullscreen is the only way you can get the graphical results you're going for, I suppose the issue is more or less moot.

Share this post


Link to post
Share on other sites

This topic is 2657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this