如何在没有指针的情况下获取 OpenGL 密钥?
我正在使用 OpenGL 绑定在 Perl 中编写一个程序,当通过读取 GLUT_WINDOW_HEIGHT 调用 glutReshapeFunc(\&changeSize); 时,我已经克服了第一个障碍> 和 GLUT_WINDOW_WIDTH 变量,但我不知道如何获取传递的键的值调用 glutSpecialFunc(\&processSpecialKeys);。 阅读 API 我找不到 GLUT_SPECIAL_KEY
变量或类似的东西。
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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenGL 本身不处理用户输入。您使用的是 GLUT,一个第三方库。
通常不会从重塑处理程序中查询 GLUT_WINDOW_HEIGHT 和 GLUT_WINDOW_WIDTH,因为这两个值都作为参数传递给函数。
因为没有。键和单击的位置作为参数传递给回调函数。
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.