Results 1 to 5 of 5

Thread: glOrtho doesn't work

  1. #1
    Newbie Newbie
    Join Date
    May 2015
    Posts
    2

    glOrtho doesn't work

    Hi guys!
    In my code, I'm using glOrtho and it doesn't make result. If I compile without glOrtho, it's the same.

    This is my code:
    Code :
    void GLWidget::initializeGL()
    {
        glClearColor(1,0,1,1);
    }
     
    void GLWidget::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT);
     
        glLoadIdentity();
     
        glBegin ( GL_QUADS );
            glColor3f(1,0,0);
            glVertex2f ( 0.0 , 0.0 );
            glVertex2f ( 0.5 , 0.0 );
            glVertex2f ( 0.5 , 0.5 );
            glVertex2f ( 0.0 , 0.5 );
        glEnd();
    }
     
    void GLWidget::resizeGL(int width,int height)
    {
        glViewport(0,0,width,height);
        const register double Left = (double)width*10/(double)height;
        glMatrixMode ( GL_PROJECTION );
        glLoadIdentity();
        glOrtho ( Left , Left , 10.0 , 10.0 , -1.0 , 1.0 );
        glMatrixMode ( GL_MODELVIEW );
        glLoadIdentity();
    }

    Does anybody know why it doesn't work?

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Code :
    glOrtho ( Left , Left , 10.0 , 10.0 , .....
    This is almost certainly not what you want; see https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
    GL_INVALID_VALUE is generated if left = right, or bottom = top, or near = far.

  3. #3
    Newbie Newbie
    Join Date
    May 2015
    Posts
    2
    Thanks

    My new Line with glOrtho
    Code :
    glOrtho ( -Left , Left , 10.0 , -10.0 , -1.0 , 1.0 );
    2 chars less and code doesn't work

    Thread to close

  4. #4
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    7
    Hi,

    I guess in opengl for ortho if (left==right) or (top == bottom) or (far == near) it will raise a invalid value error. if u quiry glGetError() u will get it. So i guess you r using ortho fun wrongly...

    Try with this "glOrtho ( 10.0 , Left , 10.0 ,Left , -1.0 , 1.0 );"

    Now it may work

    Regards,
    Nagesh

  5. #5
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Actually if you look at the documentatio for it: https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml you'll see that the generated matrix uses division by "right - left", "top - bottom" and "far - near" in a number of places.

    If these values were equal it would be division by zero.

Similar Threads

  1. second UBO doesn't work
    By mlkn_mlkn in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-11-2015, 12:34 PM
  2. glOrtho, how does it work?
    By Banangroda in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 08-11-2008, 01:21 AM
  3. glOrtho doesn't look right
    By croce in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-04-2003, 12:58 PM
  4. It doesn't work...
    By GunCraP in forum OpenGL: User Software
    Replies: 0
    Last Post: 01-03-2003, 01:46 AM
  5. Why doesn't this work
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-11-2002, 02:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean