Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Basic z coordinate usage displays blank view

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    6

    Basic z coordinate usage displays blank view

    Ok, I am a little confused on how to use z coordinates. The following code does not display a yellow triangle. When I remove the glOrtho call and change the z coordinates of the vertices back to 0.0 from 2.0 it displays. I would have expected changing all three z coordinates to affect the size of the triangle (similar to a scale). What am I missing here?
    Code :
        glClearColor(.0f, .0f, .0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable (GL_DEPTH_TEST);
        glColor3f(1.0f, 0.85f, 0.35f);
        glOrtho(-1, 1, -1, 1, 1, 100);
        glBegin(GL_POLYGON);
        {
            glVertex3f(  0.0,  0.6, 2.0);
            glVertex3f( -0.2, -0.3, 2.0);
            glVertex3f(  0.0, -0.3 ,2.0);
        }
        glEnd();

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,144
    You must not mix matrix modes. In other words, don't call glOrtho when MODELVIEW matrix is active.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    6
    Thanks Aleksander,
    I changed the code to the following but it made no difference:
    Code :
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable (GL_DEPTH_TEST);
     
        glColor3f(1.0f, 0.85f, 0.35f);
     
        glMatrixMode(GL_PROJECTION);    
        glOrtho(-1, 1, -1, 1, 1, 100);
        glMatrixMode(GL_MODELVIEW);
     
        glBegin(GL_POLYGON);
        {
            glVertex3f(  0.0,  0.6, 2.0);
            glVertex3f( -0.2, -0.3, 2.0);
            glVertex3f(  0.0, -0.3, 2.0);
        }
        glEnd();

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,144
    glViewport() is probably missing, as well as SwapBuffers(), or equivalent.
    (After adding those two commands, I get valid output from your code.)

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    6
    Let me verify something more basic. Given these two sets of vectors:
    Code :
    {-0.2f, 0.5f, -10.0f},
                {0.3f, -0.5f, -10.0f},
                {0.8f, 0.5f, -10.0f}


    Code :
    {-0.2f, 0.5f, -2.0f},
                {0.3f, -0.5f, -2.0f},
                {0.8f, 0.5f, -2.0f}

    Should these triangles appear as the same size in the view? OR asked another way, changing the Z coordinate should in fact change the apparent size of the triangle, correct?

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    6
    Quote Originally Posted by devonM View Post
    Should these triangles appear as the same size in the view? OR asked another way, changing the Z coordinate should in fact change the apparent size of the triangle, correct?
    Okay. The simple mistake in my understanding was that when using orthographic projection altering the Z coordinate does not change the size of the object whereas perspective projection does.

Posting Permissions

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