Sign in to follow this  

Constant scale orthographic projection

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

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

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