void keyboardFunc(unsigned char key, int x, int y){ if (key=='w') { ypos-=50; } if (key==27) { exit(0); }}void reshapeFunc(int x, int y){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, width/height, 1.0, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt (xpos, ypos, zpos, 0, 0, 0, 0, 1, 0);}void displayFunc(){ glClearColor(0,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gluLookAt (xpos, ypos, zpos, 0, 0, 0, 0, 1, 0); glBegin(GL_TRIANGLES); glColor3f(1,1,1); for(unsigned int i = 0; i < myMesh.nVertices*3;i+=3) { glVertex3f(myMesh.vertices[i+0], myMesh.vertices[i+1], myMesh.vertices[i+2]); } glEnd(); glutSwapBuffers();}void load(){ //load a mesh}int main(int argc, char *argv[]){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(width, height); glutInitWindowPosition(0,0); glutCreateWindow("openGL"); glutKeyboardFunc(keyboardFunc); glutReshapeFunc(reshapeFunc); glutDisplayFunc(displayFunc); load(); glutMainLoop();}
If I manually change the ypos, then the viewpoint will change,
but if I press 'w', then nothing happens. Where I am wrong?