2017-02-13 96 views
1

我无法在窗口中绘制顶点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; 
} 
+0

OpenGL使用NDC系统,x轴和y轴从-1.0到1.0 –

回答

1

display()glLoadIdentity()被消灭所述基质由gluOrtho2D()initialise()设置。

+0

现在顶点出现,谢谢@genpfault。 –

+0

顶点0,0如何绘制呢? –