Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: Ortho Setup

  1. #21
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    Code:
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    //gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
    //glOrtho(-50, 50, -37.5, 37.5, 0, 100);
    glMatrixMode(GL_MODELVIEW);
    Removing the comments on 'gluPerspective' and compiling works - everything's 3d.
    Removing the commetns on 'glOrtho' and compiling works - everything's "2d" (ortho). (Yeah I heard you say it's not realy 2d, but I like to think of it as 2d... )
    -Both works! They just don't work at the same time!
    I can't seem to "switch back" from ortho to 3d... I've tried calling 'gluPerspective' again... I've tried calling 'glMatrixMode' before/after in diffrent orders... I've tried lots of stuff... it just won't work!
    I don't know what to do!

    Ow and the rendering doesn't work unless I call 'GL_MODELVIEW' after 'gluPerspective'/'glOrtho' (nothing's shown), just a though cuz it looks like you (rev'en) don't have to... unless you call it somewhere else...

  2. #22
    Join Date
    Jan 2003
    Location
    Cookie Jar
    Posts
    971
    Code:
    glViewport(0, 0, width, height);
    
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    
    if(viewport == perspective)
    	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
    else
    	glOrtho(-50, 50, -37.5, 37.5, 0, 100);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    Obviously you'll need to modify "if(viewport == perspective)" to whatever you want to use.

    *Points out there is an OpenGL API section of this forum*
    Last edited by MVP; 08-10-2006 at 05:55 PM.

  3. #23
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    Ow you mean I should use 'glViewport' every time I switch between ortho/3d? Seems a bit.. repeating...

    Well... I tried that too... using the same code at startup as when drawing, exept for switchin' between 'glOrtho' and 'gluPerspective'...
    -Nope! everything's black!
    Or well for a millesecond it all was displayed... yeah, that has to be the first time... but when changing back to 3d and drawing the next time doesn't work..

  4. #24
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    763
    Yeah, when you set it to ortho, you have to set it each time you do a different projection. And you will have to set glMatrixMode() to projection and you will have to load the identity matrix again.
    I didn't mean to do it.

  5. #25
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    oh, good to know... still can't get it to work though...

  6. #26
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    763
    What do you do when you change projection?
    I didn't mean to do it.

  7. #27
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    EEK!! IT WORKS!!

    I was just about to show you my code when I noticed that 'glLoadIdentity' wasn't used. I made some quick changes... added them... and voĆ­la! It works!

    Man I could swear I've already tried this exact same thing many times before... ow, well... I bet those times I didn't use 'glViewport' again... anywas it works!!!

    Thank you everyone! Finaly, now I can sleep...

    Quote Originally Posted by MVP
    Points out there is an OpenGL API section of this forum
    -Ow right, sorry... I keep forgetting... I always post at "General Discussion"...

    Oh, one more thing...
    What does theese 2 do? I can't see any graphical diffrence weather I use them or not.

    glShadeModel(GL_SMOOTH);
    glDepthFunc(GL_LESS);


    Thx. You've all helped me alot.

    Soo tired... g'night...

    Edit: Mornin'..., I googled them and the values I'm using are default, so I removed them from the code...
    I tried other values but that looked horrible anyway...

    Thx, everyone...
    Last edited by EvilCookie; 08-11-2006 at 07:03 AM.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •