Unable to set frustum correctly.

See I’m using glFrustum(0, 1, 0, 1, 0, 1); SO I expect my quad’s (0,0) to be mapped to display window’s bottom left corner and (1,1) mapped to Top-right corner. But instead my display is blank. Can anyone tell why ?

  
// simplest.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <glut.h>

void displayTorus()
{
   printf("In Display
");
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   glColor3f(0.8, .2, .4);

// glutSolidTorus(.2, .6, 32, 64);

	glBegin(GL_QUADS);

	glVertex2f(0, 0);
	glVertex2f(0, 1);
	glVertex2f(1, 1);
	glVertex2f(1, 0);
	
	glEnd();

   glutSwapBuffers();
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
	glutCreateWindow("Simple Glut");
	glutDisplayFunc(displayTorus);

	glMatrixMode(GL_PROJECTION);
//	gluPerspective(20,1,.001,1000);
	glFrustum(0, 1, 0, 1, 0, 1); 

	glMatrixMode(GL_MODELVIEW);
	gluLookAt(0,0,-5,0,0,0,0,1,0);

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glutMainLoop();

	return 0;
}

It sounds like your expecting an orthographic mapping. You should use glOrtho(…) for that kind of projection.

In addition, your objects are right on the camera and I’m guessing they’re not being “seen” by it. Try moving your vertices by 0.1 back

Reza

Thanks. Tried all suggestions, even tried glOrtho though I need perspective projection but still a blank screen is appearing all the time.

#include <stdio.h>
#include <glut.h>

void displayTorus()
{
   printf("In Display
");
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   glColor3f(0.8, .2, .4);

// glutSolidTorus(.2, .6, 32, 64);

	glBegin(GL_QUADS);

	glVertex3f(0.1, 0.1, 2);
	glVertex3f(0.1, 0.8, 2);
	glVertex3f(0.8, 0.8, 2);
	glVertex3f(0.8, 0.1, 2);
	
	glEnd();

   glutSwapBuffers();
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
	glutCreateWindow("Simple Glut");
	glutDisplayFunc(displayTorus);

	glMatrixMode(GL_PROJECTION);
	GLenum err = glGetError();
	glFrustum(0, 1, 0, 1, 1, 10);
	err = glGetError();
//	gluPerspective(20,1,.001,1000);
//	glOrtho (0, 1, 0, 1, 1, 10);
	glMatrixMode(GL_MODELVIEW);
	gluLookAt(0,0,-5,0,0,0,0,1,0);

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glutMainLoop();

	return 0;
}

For a perspective projection, you should probably look at gluPerspective instead of glFrustum. It doesn’t sound like you understand glFrustum very well. Also, for a perspective projection you should always have the near plane > 0.

Here’s just a quick explanation of how you can think of glFrustum… for more detailed calculations, you should become friends with Google.

Picture your eye at the 0,0,0 point of a pyramid. The near defines how far from your eye the top of the pyramid will be chopped off. The far value defines what the bottom of the pyramid will be. The left, right, top, bottom define the size of the rectangle that is cut by the near plane.

So, basically by specifying 0, 1 for left/right, and 0, 1 for top/bottom you are already skewing the shape of the viewing volume. You esentially have a pyramid where the point isn’t in the middle, but right above one of the corners.

I’ll attempt a rough ascii drawing of what you get…

Top view of pyramid.  (x indicates the apex)

------
|   /|
|  / |
| /  |
|/   |
x-----

Side view:

x
|\
| \
|  \
|   \
-----

Notice that if you keep the size left/right, top/bottom the same, but change the distance to the near plane, your field of view changes drastically. And as that distance approaches 0, you can run into problems.

Essentially, you end up getting a field of view based on the distance of the near plane and the size of the near plane (determined by left/right top/bottom).

you havent used gluLookAt (). this might be the
reason for the blank screen.
use gluLookAt(0,0,5,0,0,0,0,1,0); to position
the camera 5 units away from the screen on z axis