2012-03-10 35 views
1

即时通讯不知道主题是否说,但我想要做的是即使没有释放鼠标左键,也能够使用多个MouseFunc条目。
在当前状态下,整个程序一直卡住,直到释放左键。即使没有释放鼠标按钮,是否可以导致继续的GLUT MouseFunc条目?

+0

我们可以看到一些代码吗? – 2012-03-10 19:06:28

+1

OpenGL不处理用户输入。 OpenGL只绘制事物。 – datenwolf 2012-03-10 19:08:08

+0

Nicol Bolas:没有什么可以发布的,因为我不知道应该写什么代码,我知道只有当其中一个按钮被释放时,MouseFunc才会退出。 – 2012-03-10 19:54:49

回答

1

glutPassiveMotionFunchttp://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(); 
} 
+0

GlutPassiveMotionFunc不处理'OnMouseClick'事件,只有x,y changings – 2012-03-10 19:53:48

+0

@igalk:然后查看glutMotionFunc,在相同的手册页中介绍。使用事件处理函数更新变量并注册一个空闲函数,该函数将这些变量的值处理为绘制下一帧的状态,然后调用glutPostRedisplay。 – datenwolf 2012-03-10 22:09:42

+0

我不太确定我是否跟着你,你能详细解释一下吗? – 2012-03-11 20:43:23

相关问题