Direct3D Z order question

Aric Cyr Aric.Cyr at gmail.com
Mon Feb 13 09:33:05 CST 2006


Stefan Dösinger <stefandoesinger <at> gmx.at> writes:

> 
> > Seems to me that the call to glOrtho should be replaced by a call to
> > glViewport(x,y,width,height) and glDepthRange(near,far).  Since your
> > vertices are already in viewport coordinates, according to the comment in
> > the code, how does something like the following work for you:
> 
> >             glViewport(X, Y, width, height);
> >             checkGLcall("glViewport");
> >
> >             /* depth ranges will be clamped to [0, 1] */
> >             glDepthRange(minZ, maxZ);
> >             checkGLcall("glDepthRange");
> That code breaks half-life. The hl console is only dark brown rectangle in the 
> top right quarter, the in-game graphics isn't drawn.

what about a combination of this plus the original glOrtho() call?  It is
possible that no projection matrix was set up at all I guess.

> What's the difference between glOrtho and glViewport/glDepthRange? I've 
> expected the code to be equal to the glOrtho call.

glOrtho multiplies to the current matrix (usually GL_PROJECTION) to define a
transformation from eye to clip space.  Clip space is a cube with each dimension
in the range [-w,w] centered on the origin, which turns out to be convenient for
clipping (w is the clip coord w value).  So all vertices are multiplied by the
projection matrix (as generated by glOrth0 or glFrustum), then they are clipped
and then divided by w to get "normalized device coordinates" where each axis is
bounded on [-1,1].  You can then imagine the vertices are being projected onto
the near clip plane (any plane parallel to the near or far clip plane would do
just as well, and would be identical).  Then the projected points on this plane
being mapped into a window whose size and position is defined by glViewport.  In
effect, the bounded projection plane is stretched to fit into the viewport

So to summarize, glOrtho and glViewport/glDepthRange are very different :)

I recommend you check out the Red Book, as it describes the OpenGL pipeline
quite well and simply... older versions are available online as well I believe.

Also more info at
http://www.opengl.org/resources/faq/technical/transformations.htm (9.011)

- Aric




More information about the wine-devel mailing list