Hi all,
I’m working with OpenGL for the first time and I have some problems with projection. I read this but I still don’t understand how the objects are projected to the screen. My biggest problem is that I still get confused about all these different coordinates. So what are the eye coordinates, device coordinates and normalized device coordinates and what is the difference between them? So when I draw a vertex with glVertex(a, b, c). Are the parameters a, b, c eye coordinates?
In my code I used perspective projection. So I set up the projection matrix with
gluperspective(45, aspect, 0.01, 100); aspect in this case is 1060/479
So when I construct my projection matrix like this. Does the image I see correspond to the near clipping plane of the frustum?
After setting up my projection matrix I wanted to draw a single point at the upper left corner. So I used
glBegin(GL_POINTS);
glVertex(-1, 1, -0.1);
glEnd();
But this point doesn’t show up. Doesn’t -1,1 correspond to the upper right corner?
I’m just another newbie but I think you are confusing orthographic with perspective mode. I would recommend buying a copy of the OpenGL Super Bible (5th edition, not 4th) and reading the first couple of chapters.
Hey, I’ve read chapter in the OpenGL Programming Guide.
So the parameteres I give to glVertex() are the object coordinates aren’t they? So if my ModelView Matrix is the identity matrix the object coordinates are equal to the eye coordinates, right?
So what I don’t understand is the following:
If I wanted to draw an single point (or anything else) in the upper left corner of my screen. How do I compute these coordinates?
So if my ModelView Matrix is the identity matrix the object coordinates are equal to the eye coordinates, right?
Yes.
If I wanted to draw an single point (or anything else) in the upper left corner of my screen. How do I compute these coordinates?
Generally, if you want to draw things relative to the space of the window, then you want to draw them using an orthographic projection, not a perspective one. You can use glOrtho to set up a projection matrix where the eye-space coordinates are exactly equal to the window-space coordinates.
Yes, but I have to use a perspective projection because the API call of the camera requires a perspective projection. Otherwise I get an distorted image.
So, is there any possibility to compute the coordinates using perspective projection?
Yes, but I have to use a perspective projection because the API call of the camera requires a perspective projection
You don’t have to do anything. You have complete control over the projection and modelview matrices; they can be exactly what you want them to be.
You can render with a perspective projection for a time, then switch to an orthographic one to do some text drawing or whatever, then back to a perspective one, then back, all within a single frame.
OpenGL does what you tell it to do; don’t limit yourself by what it seems like OpenGL is allowing you to do.