2017-02-13 1 views
1

Ich kann den Scheitelpunkt glVertex2f(10.0, 0.0) nicht im Fenster darstellen, aber wenn ich Punkte wie 0.8 benutze, wird es angezeigt.Ich kann keinen Scheitelpunkt in der Welt anzeigen

Height = 640 
Width = 480 

Also, ich könnte in der Lage sein, Punkte in diesem Bereich zu erraten, denke ich. Kann jemand den Fehler aufzeigen und korrigieren?

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 verwendet das NDC-System, X-und Y-Achse geht von -1.0 bis 1.0 –

Antwort

1

Die glLoadIdentity() in display() wird die Matrix durch gluOrtho2D() in initialise() gesetzt auszulöschen.

+0

Jetzt zeigt Scheitelpunkt, Danke @genpfault. –

+0

Wie wird dann der Vertex 0,0 gezeichnet? –

Verwandte Themen