Jump to content
  • Advertisement
Sign in to follow this  
playmesumch00ns

Constant scale orthographic projection

This topic is 4384 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 doing a little GUI test, and I want my GUI to stay a constant size in pixels, regardless of the size of the window it's in. The GUI is defined relative to the top-left corner of the window, and I use gluOrtho2d to define the projection like so:
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, 600, 0, 600 );
	
glTranslatef( 0, 600 0 );
glScalef( 1, -1, 1 );
	
glViewport( 0, 0, 600, 600 );
	
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

600 is the width and height of the initial window. I'm keeping them constant here as I DONT want the gui elements to scale when the window resizes. i.e. I want the coordinate system to stay the same andbe exactly the same as the integer coordinates I get through from glut's x, y parameters to glutMouseMoveFunc etc. Has anyone done this before, or know what I should be doing?

Share this post


Link to post
Share on other sites
Advertisement

glViewport(0, 0, window_width, window_height);
glMatrixMode(GL_PROJECTION)
glLoadIdentity();
glOrtho(0, window_width, window_height, 0);

There, origin in the upper left corner, with positive Y-axis downwards.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!