如何在没有指针的情况下获取 OpenGL 密钥?

发布于 2025-01-03 13:43:43 字数 1265 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2025-01-10 13:43:43

OpenGL 本身不处理用户输入。您使用的是 GLUT,一个第三方库。

glutReshapeFunc(\&changeSize);通过读取 GLUT_WINDOW_HEIGHT 和 GLUT_WINDOW_WIDTH 变量来调用,

通常不会从重塑处理程序中查询 GLUT_WINDOW_HEIGHT 和 GLUT_WINDOW_WIDTH,因为这两个值都作为参数传递给函数。

当 glutSpecialFunc(\&processSpecialKeys); 时传递的密钥被称为。阅读 API 我找不到 GLUT_SPECIAL_KEY 变量或类似的东西。

因为没有。键和单击的位置作为参数传递给回调函数。

OpenGL itself doesn't deal with user input. What you are using is GLUT, a 3rd party library.

glutReshapeFunc(\&changeSize); is called by reading the GLUT_WINDOW_HEIGHT and GLUT_WINDOW_WIDTH variables,

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.

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.

Because there isn't. The key and the position of the click are passed as parameters to the callback function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文