Hey everyone! I hope someone well versed in OpenGL can help me out with a problem I'm having.
I'm drawing 2D stuff with OpenGL in immediate mode. I'm using orthographic projection and setting the viewport to contain the entire window. Here's an example:
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
//
// draw stuff
//
Everything looks good at that size. Now, how do I scale or resize everything that I draw so that it will look good in a window of different dimensions?
If I draw a rectangle like so:
glBegin(GL_QUADS);
glVertex2i(20, 100);
glVertex2i(40, 100);
glVertex2i(40, 150);
glVertex2i(20, 150);
glEnd;
It will look just how I want it to look if the window has its original dimensions. If I change the width and height of the window, the rectangle stays the same, but I want it to move and scale proportionally.
How do I figure out where the rectangle should be positioned and what dimensions it should have when I resize the window?