【问题标题】:glutMouseWheelFunc doesnt trigger callbackglutMouseWheelFunc 不会触发回调
【发布时间】:2014-04-09 07:12:24
【问题描述】:

我正在尝试使用鼠标滚动按钮实现放大或缩小操作 由 glutMouseWheelFuncopengl 中。我已经实现了如下代码:

#include<GL/freeglut.h>

void mouseWheel(int button, int dir, int x, int y)
{

    printf("in mouse wheel \n");

    if (dir > 0)
    {
        // Zoom in
        ztrans = ztrans - 1.0;
        printf("scroll in = %0.3f\n ",ztrans);
    }
    else
    {
        // Zoom out
        ztrans = ztrans + 1.0;
        printf("scroll out = %0.3f\n ",ztrans);
    }

        glutPostRedisplay();

}

    int main(int argc, char **argv)
    {
      // general initializations
      glutInit(&argc, argv);
      glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
      glutInitWindowPosition(100, 100);
      glutInitWindowSize(800, 400);
      glutCreateWindow("Rotation");

      // register callbacks
      glutReshapeFunc(changeSize); 
      glutDisplayFunc(renderScene);
      glutIdleFunc(renderScene);
      glutIgnoreKeyRepeat(1);
      glutMouseFunc(mouseButton); 
      glutMotionFunc(mouseMove); 
      glutMouseWheelFunc(mouseWheel); // Register mouse wheel function

      glEnable(GL_DEPTH_TEST);

      glutMainLoop();
      return 0;

}

在执行时,它没有调用注册的回调函数(mouseWheel)。我的系统安装了freeglut3。

【问题讨论】:

  • 你在什么操作系统上开发?我刚刚在我的带有 freeglut 的 Ubuntu 12.04 上尝试了这个,它运行良好。其他鼠标回调是否有效?
  • 我在 Ubuntu 13.04 中尝试过。是的,其他鼠标回调工作正常。
  • 在 Ubuntu 13 中可能有窗口管理器设置,它保留了用于滚动虚拟桌面或其他东西的鼠标滚轮。检查您的偏好。如果不是这样,我没有想法

标签: opengl glut freeglut


【解决方案1】:

尝试使用 static intvoid mouseWheel方法中,然后在renderScene 中使用 像这样

static int k;
static int ztrans
void mouseWheel(int button, int dir, int x, int y)
{

   k = dir; // int dir is +1 of -1 based on the direction of the wheel motion

   ztrans = ztrans + k;

}

这对我有用, 试试这个并反馈,GoodLuck。

【讨论】:

    猜你喜欢
    • 2014-01-26
    • 2010-10-09
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 2011-11-23
    • 2015-03-29
    相关资源
    最近更新 更多