I’m doing a program in Perl with the OpenGL bindings, i’ve got past the first roadblock when the glutReshapeFunc(\&changeSize); is called by reading the GLUT_WINDOW_HEIGHT and GLUT_WINDOW_WIDTH variables, but i have no clue how to get the value of the key passed when glutSpecialFunc(\&processSpecialKeys); is called.
Reading the API i couldn’t find a GLUT_SPECIAL_KEY variable or anything like that.
sub changeSize
{
my $w = glutGet(GLUT_WINDOW_WIDTH);
my $h = glutGet(GLUT_WINDOW_HEIGHT);
if($w eq 0){
$w = 1;
}
my $ratio = ($w / $h);
# Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
#// Reset Matrix
glLoadIdentity();
#// Set the viewport to be the entire window
glViewport(0, 0, $w, $h);
#// Set the correct perspective.
gluPerspective(45,$ratio,1,1000);
#// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
gluLookAt( $x, 1.0, $z,
$x+$lx,1.0,$z+$lz,
0.0,1.0,0.0);
}
sub processSpecialKeys
{
$fraction = 0.1;
$key = $_[0]; #my first shot was that the key value was stored at $_[0]
#the mouse_x was at $_[1] and $_[2] had mouse_y
if ($key eq GLUT_KEY_LEFT)
{
$angle -= 0.01;
$lx = sin($angle);
$lz = -cos($angle);
}
}
OpenGL itself doesn’t deal with user input. What you are using is GLUT, a 3rd party library.
You normally don’t query GLUT_WINDOW_HEIGHT and GLUT_WINDOW_WIDTH from the reshape handler, since both of those values are passed as parameters to the function.
Because there isn’t. The key and the position of the click are passed as parameters to the callback function.