use glut
im not sure if u know but
there are more than one function for each device sometimes
depending on what they do
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
/* MOUSE */
glutWarpPointer(mid_x, mid_y);
glutSetCursor(GLUT_CURSOR_NONE);
glutMouseFunc(mousePress);
glutMotionFunc(mouseMove);
glutPassiveMotionFunc(mouseMove); //check for mouse movement
/* KEYS */
glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
glutKeyboardFunc(keyboard);
glutKeyboardUpFunc(keyboardup);
glutSpecialFunc(specialkeyboard);
glutSpecialUpFunc(specialkeyboardup);
glutMainLoop();
void keyboardup(unsigned char key, int x, int y) {
//glutIgnoreKeyRepeat(1);
/* avoid thrashing this procedure */
usleep(100);
int tex = 1;
switch (key) {
case ESCAPE: // kill everything.
exit(1);
break; // redundant.
case 'a': case 'A': // switch the blending
ambOn = ambOn ? 0 : 1;
printf("amb is now: %d
", ambOn);
break;
case 'd': case 'D': // switch the blending
difOn = difOn ? 0 : 1;
printf("dif is now: %d
", difOn);
break;
/*
case ‘b’: case ‘B’: // switch the blending
blend = blend ? 0 : 1;
if (blend) {
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
} else {
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
printf("Blending is now: %d
", blend);
break;
*/
case 't': case 'T': // switch the blending
tex = tex ? 0 : 1;
if (!tex) {
glEnable(GL_TEXTURE_2D);
} else {
glDisable(GL_TEXTURE_2D);
}
printf("Textures is now: %d
", tex);
break;
case 'l': case 'L': // switch the lighting
light = light ? 0 : 1;
if (light) glEnable(GL_LIGHTING);
else glDisable(GL_LIGHTING);
printf("Lighting is now: %d
", light);
break;
case '-': case '_': // switch the lighting
if (light_intensity <= 0) return;
light_intensity -= 0.1;
break;
case '=': case '+': // switch the lighting
if (light_intensity >= 1) return;
light_intensity += 0.1;
break;
case '{': case '[': // switch the lighting
if (light_id <= 0) return;
light_id -= 1;
break;
case '}': case ']': // switch the lighting
//if (light_id >= 1) return;
light_id += 1;
break;
/*
case ‘.’: // switch the lighting
//if (light_id >= 1) return;
f0 += 5;
break;
case ',': // switch the lighting
//if (light_id >= 1) return;
f0 -= 5;
break;
case 'm': // switch the lighting
//if (light_id >= 1) return;
f1 += 5;
break;
case 'n': // switch the lighting
//if (light_id >= 1) return;
f1 -= 5;
break;
case 'b': // switch the lighting
//if (light_id >= 1) return;
f2 += 5;
break;
case 'v': // switch the lighting
//if (light_id >= 1) return;
f2 -= 5;
break;
*/
case 'v': case 'V': // switch the lighting
camera.perspective = camera.perspective ? 0 : 1;
printf("camera.perspective is now: %d
", camera.perspective);
break;
case 'c': case 'C': // drop crate
dropCrate();
break;
default:
printf ("Key %d pressed. No action there yet.
", key);
break;
}
keyboard_state = 0;
}