无法在世界中显示顶点

时间:2017-02-13 17:33:33

标签: c++ opengl

我无法在窗口中绘制顶点glVertex2f( 10.0, 0.0 ),但是当我使用0.8之类的点时,它会显示出来。

Height = 640
Width = 480

所以,我猜我可以在这个范围内绘制积分。任何人都可以指出错误并纠正它吗?

Code:
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <cstdlib>

//defining constants
#define MAX_WIDTH 640
#define MAX_HEIGHT 480

//display callback function
void display(){

    glClear( GL_COLOR_BUFFER_BIT );

    glPointSize( 5 );

    glLoadIdentity();
    gluLookAt( 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 1.0, 0.0 );

    glBegin( GL_POINTS );
        //setting the pointer color
        glColor3f( 1.0, 1.0, 1.0 );
        glVertex2f( 0.0, 0.0 );
        glVertex2f( 10.0, 0.0 );

    glEnd();

    glFlush();
}

//catching keyboard events
void keyboardEvent( unsigned char c, int x, int y ){

    if( c == 27 ){
        exit(0);
    }
}

//catching mouse click events
void mouseEvent( int button, int state, int x, int y ){

    //checking if the mouse button is clicked or not using state para.
    if( state == GLUT_DOWN ){

        if( button == GLUT_LEFT_BUTTON ){

        }
        else if( button == GLUT_RIGHT_BUTTON ){

        }
    }
}

//adjusting window when it is moved or resized
void reshape( int w, int h ){

    glViewport( 0, 0, w, h );
}

//initialising the window at startup
void initialise(){

    glClearColor( 0.0, 0.0, 0.0, 1.0 );
    gluOrtho2D( 0, MAX_WIDTH, 0, MAX_HEIGHT );

}

int main( int argc, char **argv ){

    //initialising the glut library
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
    glutInitWindowSize( MAX_WIDTH, MAX_HEIGHT );
    glutInitWindowPosition( 100, 100 );
    glutCreateWindow("DDA Assignment");

    //calling normal functions
    initialise();

    //registering callback functions
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboardEvent );
    glutMouseFunc( mouseEvent );
    glutReshapeFunc( reshape );

    glutMainLoop();

    return 0;
}

1 个答案:

答案 0 :(得分:1)

glLoadIdentity()中的display()正在消除gluOrtho2D()initialise()设置的矩阵。