Jump to content
  • Advertisement
Sign in to follow this  
schattenmaennlein

OpenGL pseudo2dengine

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

im coding an opengl pseudo 2d engine, right now my problem is how to create a relation between the opengl matrix and my 2dcoordinatesystem. For example if I wanted a sprite do be drawn at 765|250 on the screen I wouldnt know how to tell opengl how to do this.

Share this post


Link to post
Share on other sites
Advertisement
other question: mayybee i dont need this, how do I find out where the mouse "is" in the openglmatrix? This should be easy if I can tell where the middle of the screen or a border point is and how much a pixel in opengl-units is.

So I guess all my problems boil down to: how does opengl calculate its perspective, how much is a unit with which kind of zoom, how do I configurate this and how can I calculate this?

Share this post


Link to post
Share on other sites
If you're working entirely in 2 dimensions, there's no need to worry about perspective. Just set up an orthographic projection as opposed to a perspective one. Use gluOrtho2D(left, right, bottom, top) or glOrtho(left, right, bottom, top, zNear, zFar) to set it up.

Let's say your monitor is 1024x768 and you want one OpenGL unit to equal one pixel. You would set up the orthographic projection like this:

glViewport(0, 0, 1024, 768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1024, 0, 768);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);


Then when you render your sprite at (765,250) it will be 765 pixels from the left of the screen and 250 pixels from the bottom. If you decide you want the screen to be say 40 units across and 30 units high you could say this: gluOrtho2D(0, 40, 0, 30). Or you could place the origin in the center of the screen like this: gluOrtho2D(-20, 20, -15, 15).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!