2017-02-13 43 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如何繪製呢? –