Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Ortho Setup

  1. #1
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877

    Ortho Setup

    Hey,

    I need to get (OpenGL) ortho working... This is what I do to set it up..., well, this is practically the only thing I do but to draw:
    Code:
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glOrtho(0, width, 0, height, -1, 1);
    -It seems to work at first, but something... just doesn't look right...
    -Everyrthing's stretched that's what!! Eeek!!

    It apears as if OpenGL thinks the window is a square (same width as height), but since the width is larger than the height everything apears stretched...
    And when I draw a square in just front of the "camera" it takes up the whole window's though it should end before the window's x-borders...

    Everything apears to work as it should exept that it is stretched.
    Does anyone know why this might happen?

    Thanks!
    Last edited by EvilCookie; 08-08-2006 at 10:22 AM.

  2. #2
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    Hmmm... nooo... everything got black...

  3. #3
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    753
    Sorry, try this:

    Code:
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
    float ratio = width / height;
    
    glOrtho(-100.0 * ratio,   100.0 * ratio,
               -100,          100.0,
                1.0,  -1.0);
    
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  4. #4
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    nope... black...

    Edit: maybe someone has an extremly simple example of orthographics that works that I could take a look at...?
    Last edited by EvilCookie; 08-08-2006 at 02:26 PM.

  5. #5
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    753
    Grab a copy of OpenGL Super Bible 3rd Edition by Richard Wright - has EVERYTHING you need to know plus code. Goes into great detail. Buy this one book if nothing else.

    From memory, I think you can also download the Red and Blue books from http://www.opengl.org

    Could you post your complete code here so I can have a look and compile to see what's up?
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  6. #6
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    There's a "blue book" too?? I've only got "the red book".

    Quote Originally Posted by wozdac
    Could you post your complete code here so I can have a look and compile to see what's up?
    -Well it's accually an empty OpenGL-window... every attempt to make Ortho work has been a modify to the code, since it hasn't worked I've changed it back...

    Though I could send you the code, even if it's not any ortho-stuff yet, for you to look at and tell me what to do? Dunno...

    Well if so here it is...

    In SetupGLWindow.h this is what I've been trying to modify:
    Code:
    // === Set Viewport... and stuff... ===
    glViewport(0, 0, res_x, res_y);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(GL_PROJECTION);
    gluPerspective(45.0f, (GLfloat)res_x/(GLfloat)res_y, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    (Note that I... for some reason call the variables res_x and res_y, and not width/height, otherwize the resolution is set to 640x480)
    -The other stuff, like the drawing, is in MainLoop.h.
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2003
    Location
    Cookie Jar
    Posts
    971
    Code:
        // Set Viewport to window dimensions
        glViewport(0, 0, mWindow->GetScreenWidth(), mWindow->GetScreenHeight());
    
        // Reset coordinate system
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
        glOrtho (-10, 10, -10, 10, 0, 120);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    Works for me, Im havent looked at your code yet so dunno why the black screen.

    Edit: Probably seeing black because that is what your glClearColor is set to, your scene isnt in the cameras view maybe.

    Im an OpenGL n00b so I may not know what Im talking about.
    Last edited by MVP; 08-09-2006 at 10:16 AM.

  8. #8
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    OMFG! That worked for me!

    ...ow, no... stretched again... and for some reason a couple of vertices didn't get lighted...

    Though when I changed the argumments in 'glOrtho(-10, 10, -10, 10, 0, 120)' from -10 to 0 and 10 to the width and the height everything got black again (yes, black is the "background color", aka clearcolor), but when I looked towards the ground with the camera I could see what I was drawing! Exept it was in the left-right corner of the screen and it was VERY small, like if it was very distant...

    Shouldn't the argumments be 0,width, 0,height - I thought that would select the entire window as an "ortho drawing area" - just like in 'glViewport'!

    isn't that so? what did I miss? what did I miss?

    Edit: Uploaded a pic; this is how the supose to be-square looks like...
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	stretched - should be a square.PNG 
Views:	59 
Size:	5.4 KB 
ID:	51738  
    Last edited by EvilCookie; 08-09-2006 at 10:50 AM.

  9. #9
    Join Date
    Jan 2003
    Location
    Cookie Jar
    Posts
    971
    You have to do some multiplication by the aspect ratio to get rid of the stretching.

    If width > height then you need to multiply the width by the aspect ratio, else multiply the height by it. If you dont know why, try it out for yourself on paper.

    The width and height in glOrtho isnt in pixels, its in opengl units. If your trying to make a GUI, set the viewport in window pixels and then scale all your GUI objects accordingly.
    Last edited by MVP; 08-09-2006 at 12:22 PM.

  10. #10
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    877
    I'm sorry, I'm not quite sure what I'm supose to do... =(

    I wikid aspect ratio and it said that the television's aspect ratio is 4:3, or 1.33:1.
    I tried to multiply the height by 1.33, like this, since width is larger than the height:

    glOrtho (0, res_x, 0, res_y*1.33, 0, 100);

    but nothing was displayed (everythin' black), and I looked at your example seeing you used -10, 10, -10, 10... I used 0 and not negative X!

    Instead I tried this:

    glOrtho (-(res_x/2), res_x/2, -((res_y*1.33)/2), (res_y*1.33)/2, 0, 100);

    But the result was... well check the uploaded image...

    What should I be doing? -_-' How should I "scale"?
    ...or was the aspect ratio 1:33:1 meccuring the x/y relativly to the diagonal?

    >.< heeelp...

    Btw; You have -10,10,-10,10 - what's the width/height?

    Thx.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	aspect what.PNG 
Views:	57 
Size:	14.2 KB 
ID:	51764  

Page 1 of 3 123 LastLast

Posting Permissions

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