2

this is probably a pretty basic question but I can't seem to get OpenGL to work with a point coordinate system. Instead it seems to be in percents, for example .99 puts me right at the edge of the screen. Is this how it is, or am I doing something wrong? Thanks!

code used:

#include <iostream>
#include <stdlib.h>
#include <GLUT/GLUT.h>

void RenderScene()
{
    glLoadIdentity (); 
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin( GL_POINTS );  

        glVertex3f( 0, 0, 0 );

    glEnd();


    glFlush();  
}

int main(int argc, char **argv)
{
    glutInit( &argc, argv );                
    glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );        
    glutInitWindowSize( 600, 600 );        
    glutCreateWindow( "OpenGL" );   
    glutDisplayFunc( RenderScene );
    glutMainLoop();
    return 0;
}
1
  • Maybe the answers to this question will provide you some insight into OpenGL's transformation pipeline. Oct 14, 2011 at 18:33

3 Answers 3

6

OpenGL works in the following way: You start of a local coordinate system (of arbitrary units). This coordinate system is transformed to so called eye space coordinates by the model-view matrix (it is called model-view matrix, because it combines model and view transformations).

The eye space is then transformed to clip space by the projection matrix, immediately followed by the perspective divide to obtain normalized device coordinates ( NDC{x,y,z} = Clip{x,y,z}/Clip_w ). The range [-1,1]^3 in NDC space is mapped to the viewport (x and y) and the set depth range (z).

So if you leave your transformation matrices (modelview and projection) identity, then indeed the coordinate ranges [-1,1] will map to the Viewport. However by choosing appropriate transformation and projection you can map from Model Space units to Viewport units arbitrarily.

2
  • Are you sure about Clip{x,y,z}/Clip_w ? What if I have my triangles at Z=1000. Are they thrown away? Isn't it division first, clipping after htat? May 15, 2013 at 11:30
  • @IvanKuckir: The OpenGL specification defines that clipping happens before the homogenous divide.
    – datenwolf
    May 15, 2013 at 21:09
1

It's not really a percentage: it's related to the size and aspect ratio of your current viewport. I could write a whole story about it, but I'd suggest you take a look at NeHe's tutorials on OpenGL, starting with lesson 1 about setting up the window. Very thorough, and highly recommended.

1

you are missing the projection matrix concept.

Essentially, a projection matrix is matrix that projects a vertex on a 2D space. There are two projection matrices: perspective and orthographic.

The current projection matrix determine the effective vertex screen position. Since you do not set the projection matrix, you are using the default one, which is the orthographic, with horizontal and vertical range -1 .. +1.

To control the projection matrix, see gluOrtho2D function. There you can find all information required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.