Sign in to follow this  

Need help thinking outside of just x,y pixels for 2D game

This topic is 2659 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

I'm a complete beginner to OpenGL, having done the first couple of NeHe tutorials a while back. I want to start work on a simple 2D game in which I was planning to have a simple background image (which is the map with scenery etc) and have a single player sprite move (up, down, left, right), colliding when I detect that the requested coordinates would place the character in a non-walkable part of the background image.

What I can't get my head around is the units used in OGL. The NeHe tutorials draw the square/triangle shapes, for example, by moving 1.0f on x, then 1.0f on y, but I'm trying to think of those as pixels and I'm getting confused.

In this case, let's say my background image is 600 x 600 pixels, and my character sprite is 16 x 16, how does that work with OGL? Do I create a quad and texture map the image onto it, then do the same for the sprite? Ultimately I want this to be full screen but on different devices that will have different screen sizes - if that makes any difference to how I should be approaching this.

Maybe pixels don't matter, but then how do I control the size of things? Any help about where I'm going wrong mentally would be appreciated.

Thanks.

Share this post


Link to post
Share on other sites
All of this depends how you set up your projection (presumably orthogonal). You can speciy the height and width to be however many pixels you want and match it with the window size so they are indeed pixels. As you state though, this may mess up if you have different window sizes/full screen.

Its simple to think it pixels so thats a good start. You can say your view is 600*800 and then stretch is to say 1024*768 but the "units" will still go from 0-800/0-600, they'll just take up more than one pixel on screen now.

As you say at the end, pixels don't matter. Its up to you how you want to do things, you could say far left of the "world" is 0, while far right is 1. I think your on the right track by using pixels though, its intuitive and will make things alot easier.

Some things to consider:
Will you make everything big and scale down or
Will you make everyhting small (800*600) and scale up as needed (just by changing the window size).
What will you do about different aspect ratios?

Share this post


Link to post
Share on other sites
Nanoha,

Thanks for all the clarifications. I didn't know about OGL orthogonal projection, so I'll start by looking into that. From the quick sample I just took a look at, it seems quite straight-forward and that's exactly what I want (0, width, 0, height).

Being able to code against an x by y surface (mapping directly to the background texture) and then scaling to the window size would be ideal.

For now I think I'll just force one aspect ratio and force the game to be played in landscape mode only.

In terms of OGL, am I right in thinking that I need one initial quad that I texture map the background image to, and then create additional quads over that for the sprites?

Thanks again for the help, lots of things have been clarified for me here and I feel much more comfortable in trying to go that direction now.

Share this post


Link to post
Share on other sites
Quote:
Original post by mart1986
In terms of OGL, am I right in thinking that I need one initial quad that I texture map the background image to, and then create additional quads over that for the sprites?


That should do it. Just take care with depth, either draw the background first (and then everything else on top) or give it a higher depth (z component) than the rest.

Share this post


Link to post
Share on other sites

This topic is 2659 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