Sign in to follow this  
Mr_Ridd

2D Game

Recommended Posts

Hey I'm making a 2D game with sprites, like they do in Diablo and Starcraft. Which camera view do I use? Would I have have to use gluLookAt or is there something specifically for 2D. Thanks

Share this post


Link to post
Share on other sites
The most basic way is to scale and translate the X and Y coordinates (using glScale/glTranslate) to a convenient range. By default the screen extends from (-1,-1) to (1,1). Then use the glVertex2* functions to draw everything (instead of glVertex3* etc) and ta-da, 2D OpenGL.

gluOrtho2D() is actually just a convenient way to specify the translation/scale.

glOrtho() otoh takes care of Z too, which gives you a more convenient setup if you want to insert 3D models into the scene rather than just sprites.

BTW speed should not really make much difference, all it's doing is setting up a matrix once per frame (or even only when the window is resized!). That's a very fast operation compared to actual drawing.

Share this post


Link to post
Share on other sites
Actually, that's a good point. If you set up a Z range too, you can have your sprites automagically appearing in the right order regardless of draw order... although you will have to sort them anyway if you're going to do any transparent effects.

@nife: gluOrtho has two less parameters, so it has to be faster! right? umm... :P

Share this post


Link to post
Share on other sites

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