Odd behavior when resizing windows

Hi all,

I have added the following to the draw function of the basic_template:


glTranslatef(-1.5f,0.0f,-6.0f);						// Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES);								// Drawing Using Triangles
	glVertex3f( 0.0f, 1.0f, 0.0f);					// Top
	glVertex3f(-1.0f,-1.0f, 0.0f);					// Bottom Left
	glVertex3f( 1.0f,-1.0f, 0.0f);					// Bottom Right
glEnd();											// Finished Drawing The Triangle
glTranslatef(3.0f,0.0f,0.0f);						// Move Right 3 Units
glBegin(GL_QUADS);									// Draw A Quad
	glVertex3f(-1.0f, 1.0f, 0.0f);					// Top Left
	glVertex3f( 1.0f, 1.0f, 0.0f);					// Top Right
	glVertex3f( 1.0f,-1.0f, 0.0f);					// Bottom Right
	glVertex3f(-1.0f,-1.0f, 0.0f);					// Bottom Left

Some may notice, that this is directly from NEHE’s lesson02

The odd behavior that I am seeing is that when I resize the window, the objects appear to stretch for some number of pixels, then they snap back to their original size, only to start stretching again as I continue to enlarge the window.

In GLUT, the objects would grow consistantly in the X and Y plane.

I bet this is some difference that I am not seeing between the perspective, and viewpoint options between the GLUT and CPW programs but that code appears to be the same.

Any ideas?


I tested this using the template. On resizing I believe I notices the problem you had. In the set3DMatrix function there is a call to gluPerspective:

gluPerspective( 60, windowInfo.width / windowInfo.height, 1, 100 );

Unfortunately width and height are integers. When I changed the line to:

gluPerspective( 60, (float)windowInfo.width / (float)windowInfo.height, 1, 100 );

The problem went away. I’ll update this in the samples and template. Lemmie know if this fixes your problem…


Thats it!!!

Thanks Jim. I added a printf to the set3DMatrix so that I could see what was happening. Now I think I understand. It was a rounding issue.

By the way, this also fixed another odd problem that I forgot to mention. Without the (float) typecast, if the window was higher than it was wide, the objects would just vanish. Again due to rounding.

Thanks a lot for the help,