Skip to main content
There's no such function called "glOrtho2D", there's only "gluOrtho2D" OR "glOrtho" (http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml).
Source Link

Problem in glOrtho2Dwith gluOrtho2D()

I was trying to understand the glOrtho2DgluOrtho2D function. I have drawn 4 lines originating from the center reaching up to 4 corners of the screen.

You can follow the below code. osize is a variable which is used to set the parameters of glOrtho2DgluOrtho2D. It will create a window of size 2*osize.

If works fine when osize is 1. Lines reach the corners. But as I increase the value of osize, the length of the lines decreases (cross becomes smaller and does not cover the whole screen). But I think it should reach the corner.

void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    
    //glViewport(0, 0, 100, 100);
    
    glMatrixMode (GL_PROJECTION);
    float osize = 1.2;
    //glOrtho(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0, -1.0, 1.0);
    gluOrtho2D(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0);
    glMatrixMode (GL_MODELVIEW);
    
    glBegin(GL_LINES);
       glColor3f(0.0, 0.0, 1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, osize*1.0);       
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, osize*1.0);
    glEnd();
    
    glutSwapBuffers();  //includes glFlush();
}

What is the problem?

Problem in glOrtho2D

I was trying to understand the glOrtho2D function. I have drawn 4 lines originating from the center reaching up to 4 corners of the screen.

You can follow the below code. osize is a variable which is used to set the parameters of glOrtho2D. It will create a window of size 2*osize.

If works fine when osize is 1. Lines reach the corners. But as I increase the value of osize, the length of the lines decreases (cross becomes smaller and does not cover the whole screen). But I think it should reach the corner.

void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    
    //glViewport(0, 0, 100, 100);
    
    glMatrixMode (GL_PROJECTION);
    float osize = 1.2;
    //glOrtho(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0, -1.0, 1.0);
    gluOrtho2D(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0);
    glMatrixMode (GL_MODELVIEW);
    
    glBegin(GL_LINES);
       glColor3f(0.0, 0.0, 1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, osize*1.0);       
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, osize*1.0);
    glEnd();
    
    glutSwapBuffers();  //includes glFlush();
}

What is the problem?

Problem with gluOrtho2D()

I was trying to understand the gluOrtho2D function. I have drawn 4 lines originating from the center reaching up to 4 corners of the screen.

You can follow the below code. osize is a variable which is used to set the parameters of gluOrtho2D. It will create a window of size 2*osize.

If works fine when osize is 1. Lines reach the corners. But as I increase the value of osize, the length of the lines decreases (cross becomes smaller and does not cover the whole screen). But I think it should reach the corner.

void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    
    //glViewport(0, 0, 100, 100);
    
    glMatrixMode (GL_PROJECTION);
    float osize = 1.2;
    //glOrtho(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0, -1.0, 1.0);
    gluOrtho2D(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0);
    glMatrixMode (GL_MODELVIEW);
    
    glBegin(GL_LINES);
       glColor3f(0.0, 0.0, 1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, osize*1.0);       
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, osize*1.0);
    glEnd();
    
    glutSwapBuffers();  //includes glFlush();
}

What is the problem?

Tweeted twitter.com/#!/StackGameDev/status/370154947599663104
Source Link
Shashwat
  • 387
  • 3
  • 12

Problem in glOrtho2D

I was trying to understand the glOrtho2D function. I have drawn 4 lines originating from the center reaching up to 4 corners of the screen.

You can follow the below code. osize is a variable which is used to set the parameters of glOrtho2D. It will create a window of size 2*osize.

If works fine when osize is 1. Lines reach the corners. But as I increase the value of osize, the length of the lines decreases (cross becomes smaller and does not cover the whole screen). But I think it should reach the corner.

void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    
    //glViewport(0, 0, 100, 100);
    
    glMatrixMode (GL_PROJECTION);
    float osize = 1.2;
    //glOrtho(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0, -1.0, 1.0);
    gluOrtho2D(-osize*1.0, osize*1.0, osize*1.0, -osize*1.0);
    glMatrixMode (GL_MODELVIEW);
    
    glBegin(GL_LINES);
       glColor3f(0.0, 0.0, 1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(-osize*1.0, osize*1.0);       
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, -osize*1.0);
       glVertex2f(0.0, 0.0);
       glVertex2f(osize*1.0, osize*1.0);
    glEnd();
    
    glutSwapBuffers();  //includes glFlush();
}

What is the problem?