I have a main scene centered on the center of the viewport
in addition to that I want another small object to be displayed on the corner of the viewport.
The trouble is that when I draw the small object, it is transformed by the main projection transformation and appears slanted. I want the small object to have its own vanishing point centered in its center.
Is this possible which just transformations?
Asked
Active
Viewed 1,292 times
2

shoosh
- 76,898
- 55
- 205
- 325
1 Answers
1
You want your main scene to be projected in one way and your corner object to be projected in another way. This directly leads you to the solution:
void render() {
glMatrixMode(GL_PROJECTION);
setUpMainProjection();
glMatrixMode(GL_MODELVIEW);
drawMainObject();
glMatrixMode(GL_PROJECTION);
setUpCornerProjection();
glMatrixMode(GL_MODELVIEW);
drawCornerObject();
}
Perhaps you're wondering how to implement setUpCornerProjection. It would look something like this:
// let's say r is a rect, which, in eye space, contains the corner object and is
// centered on it
glFrustum(r.left, r.right, r.bottom, r.top, nearVal, farVal);
// let's say p is the rect in screen-space where you want to
// place the corner object
glViewport(p.x, p.y, p.width, p.height);
And then in setUpMainProjection() you'd need to also call glFrustum and glViewport.

Stefan Monov
- 11,332
- 10
- 63
- 120
-
I had a feeling `glViewport` needs to be involved. Thanks! – shoosh Feb 21 '11 at 22:34
-
1@shoosh: You'll benefit from learning how glViewport and glFrustum work exactly. Simplified inexact explanation: The coords you pass to glVertex are in "object space". They get transformed by ModelView, resulting in "eye space" coords [because those are the coords of the vertices when the coordinate system is centered at the eye (camera) and the coordinate system Z axis points to where the eye is looking at]. The eye-space coords are projected (flattened) *and* scaled onto a square which goes from (-1,-1) to (1,1). And then this square is stretched to exactly fill the viewport. – Stefan Monov Feb 21 '11 at 22:53
-
@shoosh: See [this link from the OpenGL FAQ](http://www.opengl.org/resources/faq/technical/transformations.htm#tran0011) for some more detail. Write a small app to experiment with different projections and viewports. Try to get exactly the results you expect without blindly trying out different numbers until it works. Draw out a frustum on paper and figure out how to create/use that frustum in OpenGL. – Stefan Monov Feb 21 '11 at 22:54