View Full Version : glOrtho question

12-11-2002, 03:24 PM
Okay, here's a simple question. What really goes on in glOrtho ()? I'm looking at this url: http://www.opengl.org/developers/documen...ortho#first_hit (http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/gl/ortho.html?glortho#first_hit)

However, when it attempts to describe how the matrix is setup, the numerators are all missing... which doesn't help.

12-11-2002, 03:46 PM
Well, I found my answer here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_8qnj.asp

However, I'm still a bit confused. Since I can't find out how to read matrix from the opengl stack (is it possible?) I managed to initialize a vertex shader and setup its trackview to store the projection into register c[0]-c[3] and inspected; I found that the matrix produced by glOrtho () was diffrent than the one that I setup. I'm not sure what I'm doing wrong... here's some sample code:

void mSetOrthographic (int left, int top, int right, int bottom, float n, float f)
float fTerm1 = 2.0f / (right - left);
float fTerm2 = 2.0f / (bottom - top);
float fTerm3 = 2.0f / (f - n);
float fTerm4 = (float) -(right + left) / (float) (right - left);
float fTerm5 = (float) -(bottom + top) / (float) (bottom - top);
float fTerm6 = (float) -(f + n) / (float) (f - n);

tMtx4x4 &m = fProjectionMtx.mGetMtx4x4();
m[0][0] = fTerm1; m[1][0] = 0.0f; m[2][0] = 0.0f; m[3][0] = fTerm4;
m[0][1] = 0.0f; m[1][1] = fTerm2; m[2][1] = 0.0f; m[3][1] = fTerm5;
m[0][2] = 0.0f; m[1][2] = 0.0f; m[2][2] = fTerm3; m[3][2] = fTerm6;
m[0][3] = 0.0f; m[1][3] = 0.0f; m[2][3] = 0.0f; m[3][3] = 1.0f;

fProjectionMtx.mSet3x4Flag( kFalse );

Any idea what I'm doing wrong?

12-11-2002, 05:06 PM
Microsoft's opengl documentation is not that inspiring - you should really get the redbook, pref. paper editon so you can study even without a computer (ie in bed, when walking, etc). You can get an older version online: http://www.opengl.org/developers/documentation/specs.html

12-11-2002, 05:34 PM
I have the redbook, but it doesn't explicitly say what the output of glOrtho () is.

12-12-2002, 12:54 AM
I think that to get matrix from OpenGL stack simply use
glGetFloatv(GL_MODELVIEW (or GL_PROJECTION) , matrix]); where matrix is a float[16]

12-12-2002, 04:27 AM
The redbook gives all the formulas used for glOrtho, glFrustum, glRotate, glTranslate, glScale, etc. in an appendix at the back of the book.

Also, I believe all the formulas used for anything OpenGL related can be found in the OpenGL specification. You can find a link to that somewhere from the main site here, under Documentation.

[This message has been edited by Deiussum (edited 12-12-2002).]