我不确定主题是否说明了但我正在尝试做的是即使没有释放鼠标左键也可以使用多个MouseFunc条目。
在当前状态下,整个程序一直停留,直到释放左按钮。
答案 0 :(得分:1)
请参阅glutPassiveMotionFunc
http://www.opengl.org/resources/libraries/glut/spec3/node51.html
示例代码:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
int mouse_x;
int mouse_y;
void draw_square(float s)
{
s /= 2.;
GLfloat v[] = {
-s, -s,
s, -s,
s, s,
-s, s
};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
}
void display(void)
{
int width, height;
width = glutGet(GLUT_WINDOW_WIDTH);
height = glutGet(GLUT_WINDOW_HEIGHT);
glClearColor(0.3, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/* mouse_y is from window top */
glTranslatef(mouse_x, height - mouse_y, 0);
glColor4f(1.0, 0.0, 0.0, 1.0);
draw_square(16);
glutSwapBuffers();
}
void mouse_motion(int x, int y)
{
mouse_x = x;
mouse_y = y;
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Mouse Motion");
glutDisplayFunc(display);
glutMotionFunc(mouse_motion);
glutPassiveMotionFunc(mouse_motion);
mouse_x = mouse_y = 0;
glutMainLoop();
}