need help in proper use of glortho

Started by
3 comments, last by hotdot 22 years, 5 months ago
Sorry I know this may sound lame but i just cant make glortho work fine in anything i try, since i want to display text and other stuff from my actual world position am i wrong to presume that glortho does not draw from current position and i should do something like matrix push ? In a second sub-topic i would really require some help to understand why do i have to use the following sequence to setup glperspective ort glortho (if any of you owns the opengl game programming book im referencing to chap 5 page 143): glMatrixMode(GL_Projection); glLoadidentity(); (i dont understand the need to reset here) glfrustrum(...) or glOrtho(...) glMatrixMode(GlModelview); glLoadidentity(); (here too i dont understand the need to clear this matrix) in either of these cases where should i pop/push to display at my current location. Thanks to anybody kind enough to help someone who has tried hard before asking for help =) May the code be with us !
May the code be with us !
Advertisement
glFrustum and glOrtho multiply the current matrix by the matrix they create. So, to make the appropriate projection matrix we switch to it, then load the identity matrix (remember that Identity*M = M), then call the function. So, to use them one after the other we do this:
  glMatrixMode(GL_PROJECTION);glLoadIdentity();glFrustum(...);glMatrixMode(GL_MODELVIEW);glLoadIdentity();for( ; ; ) { // You game''s loop  // Render 3D Stuff here  glMatrixMode(GL_PROJECTION);  glPushMatrix();  glLoadIdentity();  glOrtho(...);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  // Render 2D Stuff here  glMatrixMode(GL_PROJECTION);  glPopMatrix();  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();}  

You can also combine that with glLoadMatrix and glGet(...) if you don''t want to calculate an orthographic matrix each loop.

[Resist Windows XP''s Invasive Production Activation Technology!]
thank you i will try to modify my things to fit in that sense because the main problem i had i think in regards to this matrix product was the fact that i was drawing a mix of 3d and 2d i think my matrixes were getting mixed because it was hard getting a good result. So ill draw the 3d first and then the 2d. But its harder when all my things are done in C++... but thats my problem thanks again for the information.
May the code be with us !
Will all the calls to glMatrixMode() glPush/PopMatrix() and glEnable/Disable() cause measurable slowdown, though? (assuming you had several more than shown in that small snippet)
Surely to some extent every call to a function will slow things down. As for myself, i didnt noticed the difference and it seems to work fine.
May the code be with us !

This topic is closed to new replies.

Advertisement