I am trying to rebuild the foundation of some OpenGL programming I lost a while ago. So I am trying to get a standard quad spinning. It shows up, but every time I run it, the aspect ratio changes WILDLY, from squashing or stretching to the quad being tiny or huge. I do nothing other than start it, shut it down, start it again, over and over, with completely different results every time.
This is the code I am dabbling with for the frustum. I know the frustum stuff is completely off, but I am interested in why it changes so wildly without me changing anything?
RECT rect;
GetWindowRect(hWnd, &rect);
……..
double width = rect->right - rect->left;
double height = rect->bottom - rect->top;
double aspect = width/height;
glViewport(0, 0, width, height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
GLdouble fW, fH;
double t = 0.1 * tan(aspect*45/2);
double b = -t;
double r = aspect*t;
double l = -r;
glFrustum( l, r, b, t,0.1,100.0);
This is the drawing section. It is pretty much just copy paste:
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix ();
glRotatef (theta, 0.0f, 0.0f, 1.0f);
glBegin (GL_QUADS);
glColor3f (1.0f, 0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, -5.15f);
glColor3f (1.0f, 1.0f, 0.0f); glVertex3f (1.0f, -1.0f, -5.15f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex3f (1.0f, 1.0f, -5.15f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex3f (-1.0f, 1.0f, -5.15f);
glEnd ();
glPopMatrix ();
SwapBuffers (hDC);
theta += 1.0f;
Sleep (1);