I’m trying to use the standard glutKeyboardFunc to no avail. When I press a button my computer replies with the error chime… Any ideas? My code follows…
/* Program 2, October 21st, 2002 * Author: Dennis Falling * Purpose: To create a 3 dimensional world with fly-through camera. */ #include <GLUT/glut.h> // imports the necessary OpenGL files #include <math.h> // imports the sin,cos methods #include <iostream> // for testing purposes typedef float point[4]; // new type (array of floats) typedef float grid[4][4]; // new type (2-d array of floats) void clear() { //glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); } // end of clear method void display() { //call function to draw plane
glFlush();
}
void processNormalKeys(unsigned char key, int x, int y)
{
if (key == ‘a’)
std::cout << “‘a’ was pressed”; // this line will later be used for a camera control
else if (key == ‘d’)
std::cout << “‘d’ was pressed”;
else if (key == ‘q’)
exit(0);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); display();
}
int main(int argc, char** argv)
{glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500,500); // sets the size of the window glutInitWindowPosition(50,450); // puts the window in a nice place on my screen... glutCreateWindow("Program 2"); glutIdleFunc(display); glutKeyboardFunc(processNormalKeys); glClearColor(1.0,1.0,1.0,0.0); // white background glColor3f(0.0,0.5,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0); // specifies dimensions of viewing region gluPerspective(45,1,1,10); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(clear); glutMainLoop();
return 0; //required for program to compile
} //end of main