Include dependency graph for progs/demos/joystick/joystick.c:
Copyright (C) 2004, the OpenGLUT project contributors.
OpenGLEAN Joystick Demonstration
#include <GL/gleandev.h> #include <GL/openglean.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #define MAX_AXES 3 static float joystickAxis [MAX_AXES]; static int joystickButtons; /* GLUT callback Handlers */ static void resize (int width, int height) { const double ar = width * 1.0 / height; const double sf = .8; glViewport (0, 0, width, height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); if (ar > 1) glFrustum (-ar * sf, ar * sf, -sf, sf, 2, 8); else glFrustum (-sf, sf, -sf / ar, sf / ar, 2, 8); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); } static void drawButton (int button, int down) { glPushMatrix (); glTranslated (-.9 + .2 * button, .05, .8); glScaled (.16, .6, .16); if (down) glColor3d (1, 0, 0); else glColor3d (.4, .3, .3); glutSolidCube (1); glPopMatrix (); } static void display (void) { int button; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable (GL_LIGHTING); glPushMatrix (); glTranslated (0, -0.5, -4.5); glRotated (30, 1, 0, 0); glPushMatrix (); glScaled (2, .5, 2); glColor3d (.6, .6, .5); glutSolidCube (1); glPopMatrix (); glPushMatrix (); glRotated (-35 * joystickAxis [0], 0, 0, 1); glRotated ( 35 * joystickAxis [1], 1, 0, 0); glTranslated (0, 1, 0); glScaled (.5, 2, .5); if ((abs (joystickAxis [0]) < .001) || (abs (joystickAxis [1]) < .001)) glColor3d (1, 0, 0); else glColor3d (.3, .3, .2); glutSolidCube (1); glPopMatrix (); glPushMatrix (); glTranslated (.9 * joystickAxis [2], 0, 1.1); glScaled (.2, .5, .2); glColor3d (.5, .9, .5); glutSolidCube (1); glPopMatrix (); for (button = 0; button < 10; ++button) drawButton (button, joystickButtons & (1UL << button)); glPopMatrix (); glutSwapBuffers (); } static void joystick (int data) { int axis; int jstick = 0; /* * XXX glutJoystickReadAxis() -=> gleandevReadJoystickAxis() * XXX and should return values in the range [-1,1], floating point, * XXX rather than integers in [-1000,1000]. * * XXX Then again, should be using gleandevGetf() or gleandevGetd(). */ for (axis = 0; axis < 3; ++axis) joystickAxis [axis] = glutJoystickReadAxis (jstick, axis) / 1000; joystickButtons = glutJoystickReadButtons (jstick); glutPostRedisplay (); glutTimerFunc (50, joystick, data); } static void key (unsigned char key, int x, int y) { (void) x; /* XXX Make GCC happy */ (void) y; switch (key) { case 27: case 'Q': case 'q': exit (0); default: break; } glutPostRedisplay (); } const GLfloat light_ambient [] = {0, 0, 0, 1}; const GLfloat light_diffuse [] = {1, 1, 1, 1}; const GLfloat light_specular [] = {1, 1, 1, 1}; const GLfloat light_position [] = {2, 5, 5, 0}; const GLfloat mat_ambient [] = {.7, .7, .7, 1}; const GLfloat mat_diffuse [] = {.8, .8, .8, 1}; const GLfloat mat_specular [] = {1, 1, 1, 1}; const GLfloat high_shininess [] = {100}; /* Program entry point */ int main (int argc, char **argv) { int i; glutInitWindowSize (640, 480); glutInitWindowPosition (40, 40); glutInit (&argc, argv); glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow ("OpenGLEAN Joystick"); glutReshapeFunc (resize); glutDisplayFunc (display); //glutJoystickFunc (joystick, 50); glutJoystickInit (); glutTimerFunc (50, joystick, 0); glutKeyboardFunc (key); glClearColor (1, 1, 1, 1); glEnable (GL_CULL_FACE); glCullFace (GL_BACK); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); glEnable (GL_LIGHT0); glEnable (GL_NORMALIZE); glEnable (GL_COLOR_MATERIAL); glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv (GL_LIGHT0, GL_POSITION, light_position); glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv (GL_FRONT, GL_SHININESS, high_shininess); if (!gleandevGeti (GLEANDEV_HAS_JOYSTICK)) printf ("Joystick not detected.\n"); else { printf ("Joystick detected.\n"); printf ("%d axes.\n", gleandevGeti (GLEANDEV_JOYSTICK_AXIS)); printf ("%d buttons.\n", gleandevGeti (GLEANDEV_JOYSTICK_BUTTONS)); printf ( "Joystick %savailable.\n", gleandevGeti (GLEANDEV_OWNS_JOYSTICK) ? "" : "un" ); } for (i = 0; i < MAX_AXES; ++i) joystickAxis [i] = 0; joystickButtons = 0; glutMainLoop (); return EXIT_SUCCESS; }
Supported in part by SourceForge.net.
Generated on Fri Sep 9 18:01:32 2005 for gleandev by
doxygen 1.4.3
The OpenGLEAN project is hosted in part by
SourceForge.