#### Archived

This topic is now archived and is closed to further replies.

# need help in proper use of glortho

This topic is 6108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 !

##### Share on other sites
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!]

##### Share on other sites
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.

##### Share on other sites
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)

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002356
×