1

I am using OpenGL with the LWJGL library in java. As I understand it, you can use glFrustum to set up the top, bottom, left, right, near and far coordinates and you then use glViewport to relate those coordinates to the screen, is this correct ? I assume this because nothing I have read has said otherwise and this is how it worked when I was using orthographic mode. To expand on my question, I set up my application like this (in c syntax)

glFrustum(-100, 100, -100, 100, -100, 100);
glViewport(0, 0, 800, 600); // the screen size is 800 by 600

. . .

glBegin(GL_QUADS); //draw a rectangle
glVertex2f(-0.25f, -0.25f);
glVertex2f(0.25f, -0.25f);
glVertex2f(0.25f, 0.25f);
glVertex2f(-0.25f, 0.25f);
glEnd();

How is it possible that with a coordinates system of -100-----0-----100 on the x and y axis, that I get a rectangle of a size that looks like that the coordinates i supplied have been multiplied by 10 ?

4

1 に答える 1

3

As I understand it, you can use glFrustum to set up the top, bottom, left, right, near and far coordinates

Not quite. glFrustum creates a affine perspective projection matrix, having the shape of a pyramid with the tip cut of – a frustum. If you'd extend that pyramid to the tip, the tip was at the coordinates (0,0,0), the near parameter defines the distance of the XY plane to the tip in Z direction as where to "cut" that pyramid. The far plane gives the distance to the pyramids base. The left, right, top and bottom parameters define, where the sides of the pyramid intersect with the near plane, which means, that the pyramid is not required to be symmetric. It can be shifted as well.

and you then use glViewport to relate those coordinates to the screen, is this correct?

OpenGL is a state machine. The order in which you call set those states doesn't matter. You can change each state anytime, anyhow. The order is only important then, if the previous state contributes to the data/parameters setting the new state. The matrix operations are an example, because the operate on the previous state. But glViewport is independent of this.

How is it possible that with a coordinates system of -100-----0-----100 on the x and y axis, that I get a rectangle of a size that looks like that the coordinates i supplied have been multiplied by 10?

Because you're not building a valid frustum. The near and far planes of a frustum projection must not have opposite signs. Usually you want them to be both positive. Also the near plane distance must be nonzero.

The way you defined your "frustum" is is shaped like an hourglass. Also your vertices are at Z=0, so they're in the singularity of that frustum and anything may happen there.

I think you actually wanted a ortho projection.

于 2012-04-13T12:22:07.867 に答える