【发布时间】:2014-04-09 07:12:24
【问题描述】:
我正在尝试使用鼠标滚动按钮实现放大或缩小操作
由 glutMouseWheelFunc 在 opengl 中。我已经实现了如下代码:
#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 中可能有窗口管理器设置,它保留了用于滚动虚拟桌面或其他东西的鼠标滚轮。检查您的偏好。如果不是这样,我没有想法