Question

I was trying to clip an image on my screen by limiting the viewing volume using glFrustum. In the official documentation for Glfrustum, it is mentioned that the left, right, top, bottom, near, far are the coordinates for the clipping. I thought them to be screen coordinates and tried doing:

glFrustum(100, 924, 100, 668, 3, 1000);

The above wasn't showing anything to me on the screen. So, I just looked up somewhere and saw some code as follows (but why are those coordinates negative?):

glFrustum(-1, 1, -1, 1, 0.5, 1000);

I used the excat same thing and started getting some portion of the image on the screen. Subsequently, I treied fiddling with coordinates for near and noticed how viewing volume changes.

glFrustum(-10,10,-10,10,10,1000);
glFrustum(-100,100,-100,100,100,1000);
glFrustum(-0.5,0.5,-0.5,0.5,0.5,1000);

All the above were giving the same output of the images to me on the screen. But most of the places where I have observed glFrustum being used, I noticed the values being used somewhere from [-1,1] (such as here) and folks talking about calculations in the normalised range. Why is doing the calculation for left, right, bottom, top, near, far important (near and far also included in normalised values?) in terms of normalised values? Can the same operations be performed using the values in screen coordinates as well?

Was it helpful?

Solution

NOTE: This question and answer is only valid for older (before version 3) OpenGL.

First of all, glFrustum is independent of your screen resolution.

This function define a volume in which the scene will be drawn, that is, all element of your screne that throw outside this volume will be ignored/cut. Coordenates for glFrustum are relative to your scene, not to your screen.

enter image description here

Take in consideration that for a correct representation, other parameters must be configured correctly like scene rotation/translation, etc.

glFrustum(-10,10,-10,10,10,1000);
glFrustum(-100,100,-100,100,100,1000);
glFrustum(-0.5,0.5,-0.5,0.5,0.5,1000);

All the above were giving the same output of the images to me on the screen

Not exactly, if your 3D model is near the POV (camara), example 2 will cut it where example 3 will not. But as you increment/reduce the "near" distance in proportion to "left", "top", "bottom" and "right", the result is similar.

OTHER TIPS

Those arguments are not in the coordinate system (space) you think. I found this for you: http://www.matrix44.net/cms/notes/opengl-3d-graphics/coordinate-systems-in-opengl

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top