Am I understanding glFrustum properly

Started by
12 comments, last by LilBudyWizer 18 years, 6 months ago
Quote:Original post by LilBudyWizer
I doubt it took your glFrustum call since near is never suppose to 0 since that would make the projection matrix singular. So I would assume you have the default frustum.


You are correct. I checked and glGetError() was returning GL_INVALID_VALUE.
I've modified my code. I'm no longer getting an error. Why is the square still not visible?

	GLenum err;	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glFrustum(-320, 320, -240, 240, 1, 10);	err = glGetError();		if(err!=0)	{		MessageBox(NULL, "You dun screwed up!", "Arrr!", MB_OK);	}	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glClearColor(0, 0, 0, 0);	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glColor3f(1, 1, 1);	glTranslatef(0, 0, 2);	glBegin(GL_POLYGON);		glVertex3f(-0.5f, -0.5f, 0);		glVertex3f(0.5, -0.5f, 0);		glVertex3f(0.5, 0.5f, 0);		glVertex3f(-0.5, 0.5f, 0);	glEnd();	return true;


Your help is appreciated.
--------
Whoisdoingthis.com - my stupid website about warning labels.
Advertisement
First, the depth range of your frustum is [-1, -10] but you draw the quad at z=2, which is outside this range, and therefore not visible. You need to translate it to Z=-2 instead of Z=2.

But then there's one more thing. Your quad will be drawn correctly, but you still may not see it. At Z=-1, your frustum is 640x480 units in size (because of the values in glFrustum). That means, at Z=-2, the frustum will be 1280x960 units in size, and you draw a quad 1x1 units in size. So unless your window is at least 1280x960 pixels large, the quad will be less than a pixel large, and may not be drawn just because it's too small.

The horizontal field of view of your frustum is EXTREMELY large, close to 179.5 degrees. If you want, say, a 90 degree horizontal field of view, you should set the top and bottom parameters of glFrustum to about the same values as the near plane. Check out jyk's picture; if n is small and r and l is large, the field of view is large.

Rating++ all around.
The square is now being displayed as it should. Thanks for all the help!
--------
Whoisdoingthis.com - my stupid website about warning labels.
The fun is just beginning. One suggestion would be take advantage of the fact the coordinate system can be pretty much anything that makes drawing easy. Particularly you can have a routine that simply draws a shape and then use transforms to size, orient and position it. So for example I usually draw everything centered at the origin in a unit cube. Particularly remember that you can orient it any way that makes it easy to figure out where the vertices are.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement