View Full Version : JoyStick implementation with GLUT
Is there any function which can detect
JoyStick's data change and call the renderscene
Like glutKeyboardFunc can detect the Keyboard's
data changed .
I checked all the GLUT Callback Registration
function, but found nothing about JoyStick.
Thanks A Lot!!!
04-14-2005, 01:08 PM
Just poll it in another callback, joystick input is not generally event driven.
You don't need a callback called "handle_joystick".
Your question suggests architectural flaws. Event driven rendering is OK fo rsome GUI applications, but you really want a rendering loop with ongoing updates and rendering for animation, polling a joystick in the midst of this need not invok erendering, merely act as an input to the update function, motion and animation through rendering will happen with or without a change in joystick input.
04-15-2005, 06:53 PM
Few years ago,I wrote a program to read the joystick using an extension of glut called
gameglut.It should be part of glut 3.7 according
to Q41 of the glut FAQ section.
Here's the code I used:
int button1 = 0;
int button2 = 0;
int button3 = 0;
int button4 = 0;
int button5 = 0;
int button6 = 0;
int button7 = 0;
int button8 = 0;
int x_axis = 0;
int y_axis = 0;
int z_axis = 0;
void joystick(unsigned int buttonmask, int x, int y, int z)
x_axis = x;
y_axis = y;
z_axis = z;
if (buttonmask & 0x01) button1 = 1;
else button1 = 0;
if (buttonmask & 0x02) button2 = 1;
else button2 = 0;
if (buttonmask & 0x04) button3 = 1;
else button3 = 0;
if (buttonmask & 0x08) button4 = 1;
else button4 = 0;
if (buttonmask & 0x10) button5 = 1;
else button5 = 0;
if (buttonmask & 0x20) button6 = 1;
else button6 = 0;
if (buttonmask & 0x40) button7 = 1;
else button7 = 0;
if (buttonmask & 0x80) button8 = 1;
else button8 = 0;
glutJoystickFunc(joystick, 25);25 is the # of msec between each sampling of the
Hope it helps.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.