PDA

View Full Version : GLUT KeyboardFunc - Crash problems.



kvinther
06-06-2003, 12:46 PM
Hi, I'm using glut under Windows XP.

I have made a very basic program, which just initializes the window, and draws a rectangle. The program compiles and runs without a problem!

When I add keyboard or mouse callback functions, my program simply crashed. This is both the case using Visual C++ 6.0 and g++ under Cygwin.

I haven't been able to find someone describing a similar problem on any of the forums I know of. I tried compiling on my friends WinXP machine - which also crashed.

Here is the code:

#include <windows.h>
#include <GL/glut.h>


void glInit() {

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
glClearColor(0,0,0,1);
glColor3f(1,1,1);
}

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glRectf(1,1,2,2);

glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y) {
}

void mouse(int button, int state, int x, int y) {
}

int main(int argc, char** argv) {

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(600, 400);

glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);

glutCreateWindow("Simple");
glutDisplayFunc(display);

glInit();
glutMainLoop();
return 0;
}

Bob
06-06-2003, 02:21 PM
Set your callbacks after you create your window.

kvinther
06-07-2003, 01:48 AM
-> Bob.

Why I'd be da....

That solved the promblem, it actually makes sence to register callback to a window - after you register the window! http://www.opengl.org/discussion_boards/ubb/smile.gif

Thank you very much, I was getting pretty frustrated with this error.