0
votes

On using glFrustum,

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 0.1, 1000.0);
glLoadMatrxi(GL_MODELVIEW);
glBegin(GL_QUADS); //A room's left wall
glVertex3f(-1.0, 1.0, 0.0);
glVertex3f(-1.0, 1.0, -0.4);
glVertex3f(-1.0, -1.0, -0.4);
glVertex3f(-1.0, -1.0, 0.0);
glEnd();

All my drawings happen in -1, 1 (notice the above snippet for //A room's left wall) i.e.
X- axis: -1 becomes the left, 1 becomes the right with origin in centre.
Y-Axis: 1 becomes the top and -1 becomes the right with origin in the center

Does glFrustum automatically change my coordinates to [-1,1]?

Normally, I would draw a cube with by specifying the screen coordinates as follows:
eg: ofBox(512,384,0,10) gives me a box in the center of screen [Window width: 1024, Window Height: 768]

What if I want to keep drawing as I draw normally in my pixel coordinates and don't want to make things complex for myself by trying to convert from pixel coordinates drawing to normalised coordinates even if I use glFrustum?

1

1 Answers

3
votes

I think you're still having a hard time imagining what a frustum is, and how it relates to the projection. Simply spoken a frustum is a pyramid with its tip cut off at some distance:

frustum

If used as a OpenGL projection matrix the bounds of the frustum define a volume in view space coordinates (i.e. after the modelview transformation) that will be turned into a cube of extents {-1, 1}²×{0, 1} by the projection transformation and homogenous divide.

The extents of the near plane define the extents in view space coordinates – that is world space with the view point being placed at (0,0,0) – that will be mapped (i.e. "stretched" and/or "pinched") to the extents of the rendering window defined with glViewport.

In short words: You use glViewport to define the pixel coordinates in the window where things should go and glFrustum to sort of "cut" a slice out of view space (which is world space moved in such a way that the camera is at (0,0,0)).