Constant scale orthographic projection

Started by
1 comment, last by playmesumch00ns 17 years, 9 months ago
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?
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.
Awesome, tahnkyou! Can't believe it was so simple :)

This topic is closed to new replies.

Advertisement