Hello,
I am trying to handle Keyboard and Mouse events of GLUT in my program. It seems however that these are not handled at all. My program runs well on a Windows machine. But none of the events of keyboard or mouse are handled.
I am using Xcode, have included Opegnl framework and glut framework (and glut works I guess, since a window is created using glut and initialization etc. also works).
Following is a sample code that am trying to run:
What can be wrong or am I missing something?
Would appreciate any help!
Thanks!
I am trying to handle Keyboard and Mouse events of GLUT in my program. It seems however that these are not handled at all. My program runs well on a Windows machine. But none of the events of keyboard or mouse are handled.
I am using Xcode, have included Opegnl framework and glut framework (and glut works I guess, since a window is created using glut and initialization etc. also works).
Following is a sample code that am trying to run:
Code:
#include <stdio.h>
#include <GLUT/glut.h>
GLdouble X = 0.0, Y = 0.0;
GLdouble thetaX = 10.0, thetaY = 10.0;
void mouseFunc(int button, int state, int x, int y)
{
if (button== GLUT_LEFT_BUTTON) {
X+=0.2;
Y+=0.2;
printf("Moving up...\n");
}
if (button == GLUT_RIGHT_BUTTON) {
X-=0.2;
Y-=0.2;
printf("Moving Down...\n");
}
glutPostRedisplay();
}
void normalKeys(unsigned char key, int x, int y)
{
switch (key) {
case 'u':
X+=0.2;
Y+=0.2;
printf("Moving Up...\n");
break;
case 'd':
X-=0.2;
Y-=0.2;
printf("Moving Down...\n");
break;
case 27:
printf("Exiting");
exit(1);
break;
default:
printf("Key pressed does not have a meaning....");
break;
}
glutPostRedisplay();
}
void idle()
{
glutPostRedisplay();
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.5f, 0.5f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(X, Y, 0);
glRotatef(thetaX, 1.0f, 0.0f, 0.0f);
glRotatef(thetaY, 0.0f, 1.0f, 0.0f);
glutSolidSphere(1.0, 20.0, 20.0);
glFlush();
}
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutIdleFunc(idle);
glutMouseFunc(mouseFunc);
glutKeyboardFunc(normalKeys);
glutCreateWindow("Glut try");
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
}
What can be wrong or am I missing something?
Would appreciate any help!
Thanks!