Hello,
I’ve recently started studying OpenGL, I’m trying to make a camera fly around, I managed to get it to work however when I tried to move the camera around only while holding a mouse button it blocked the whole program as soon as I hold the button then back to running when I release, it wouldn’t access the mouseMotion function while the button is held down for some reason.
I’ve looked everywhere, most tutorials show almost the exact same code as mine yet it doesn’t work for me for some reason, any help is greatly appreciate!
This is my code if it helps:
void mouse(int button, int state, int x, int y) {
mouseState = state;
mouseButton = button;
}
void mouseMotion(int x, int y) {
cameraXRotation += x - mouseX;
cameraYRotation += y - mouseY;
mouseX = x;
mouseY = y;
}
void draw()
{
.
.
.
.
glTranslatef(camx, camy, camz);
glRotatef(cameraYRotation * cameraRotationSpeed, 1, 0, 0);
glRotatef(cameraXRotation * cameraRotationSpeed, 0, 1, 0);
.
.
.
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("test");
glutDisplayFunc(draw);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutPassiveMotionFunc(mouseMotion);
init();
glutMainLoop();
return 0;
}