Rendered Objects Won't Appear In Windowed Mode

Started by
2 comments, last by _paf 11 years, 2 months ago

I'm in the midst of learning OpenGL, using the Win API as opposed to GLEW/GLUT that's often recommended, and I'm currently plowing through Nehe's OpenGL Tutorial. I'm attempting to render a pair of three-dimensional objects and to an extent was successful. While the objects appear on the screen in fullscreen mode, if I choose to begin with or switch to windowed mode, the objects won't appear. I'm assuming it has something to do with the CreateGLWindow function that handles creating the windows regardless of display mode, because the DrawGLScene function at least remains consistent in continually drawing the same image, rendering only the background if windowed and rendering the background and objects if fullscreen. Below is the link to the source code discussed. Any assistance would be greatly appreciated, thanks.

https://gist.github.com/anonymous/5086149

Advertisement

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL
{
	if (height == 0) { // Prevent A Divide By Zero By
		height = 1;    // Making Height Equal One
	}
 
	glViewport(0, 0, width, height); // Reset The Current Viewport
 
	glMatrixMode(GL_PROJECTION);     // Select The Projection Matrix

	...

	// Calculate the Aspect Ratio Of The Window
	gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f);
 
	glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
	glLoadIdentity();           // Reset The Modelview Matrix

    //gluLookAt(0.0f, 5.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
}

You're missing a glLoadIdentity() after the glMatrixMode(GL_PROJECTION);

Brilliant! Thanks, and sorry for the inconvenience. Can someone follow up on how the missing glLoadIdentity() function affected the matrices? Does the projection matrix not being properly reset mean that the gluPerspective function determines some improper aspect ratio for windowed mode and a proper aspect ratio in fullscreen mode?

Maybe calling gluPerspective() will multiply or add with the old projection matrix, and without setting the projection matrix to the identity first, will produce incorrect results, but i'm not really sure... Though i can't really explain why it works in fullscreen mode, when the resize function is exactly the same.

This topic is closed to new replies.

Advertisement