即使鼠标按钮不在';位置,是否可能导致持续的GLUT MouseFunc输入;你没有被释放吗?

即使鼠标按钮不在';位置,是否可能导致持续的GLUT MouseFunc输入;你没有被释放吗?,glut,Glut,我不确定主题是否有这样的意思,但我想做的是,即使鼠标左键没有松开,也能打开多个MouseFunc条目。 在当前状态下,整个程序被卡住,直到松开左按钮 参见glutpassiveemotionfunc 示例代码: #include <stdlib.h> #include <stdio.h> #include <math.h> #include <GL/glut.h> int mouse_x; int mouse_y; void draw_squ

我不确定主题是否有这样的意思,但我想做的是,即使鼠标左键没有松开,也能打开多个MouseFunc条目。

在当前状态下,整个程序被卡住,直到松开左按钮

参见
glutpassiveemotionfunc


示例代码:

#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();
}
#包括
#包括
#包括
#包括
int鼠标_x;
int mouse_y;
空心画方(浮点数s)
{
s/=2。;
GLV[]={
-s、 -s,
s、 -s,
s、 s,
-s、 
};
glEnableClientState(GL_顶点_数组);
glvertexointer(2,GL_浮点,0,v);
gldrawArray(GL_三角形_扇,0,4);
glDisableClientState(GL_顶点_数组);
}
作废显示(作废)
{
int宽度、高度;
宽度=glutGet(GLUT\u窗口\u宽度);
高度=glutGet(GLUT\u窗口\u高度);
glClearColor(0.3,0.3,0.3,1.0);
glClear(GLU颜色缓冲位);
glViewport(0,0,宽度,高度);
glMatrixMode(GL_投影);
glLoadIdentity();
格洛托(0,宽度,0,高度,-1,1);
glMatrixMode(GLU模型视图);
glLoadIdentity();
/*鼠标在窗口顶部*/
glTranslatef(鼠标x,高度-鼠标y,0);
glColor4f(1.0,0.0,0.0,1.0);
画方(16);
glutSwapBuffers();
}
无效鼠标移动(整数x,整数y)
{
鼠标x=x;
鼠标_y=y;
再发现();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
创建窗口(“鼠标运动”);
glutDisplayFunc(显示器);
glutMotionFunc(鼠标运动);
GLUT被动情绪功能(鼠标运动);
鼠标x=鼠标y=0;
glutMainLoop();
}

参见
glutpassiveemotionfunc


示例代码:

#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();
}
#包括
#包括
#包括
#包括
int鼠标_x;
int mouse_y;
空心画方(浮点数s)
{
s/=2。;
GLV[]={
-s、 -s,
s、 -s,
s、 s,
-s、 
};
glEnableClientState(GL_顶点_数组);
glvertexointer(2,GL_浮点,0,v);
gldrawArray(GL_三角形_扇,0,4);
glDisableClientState(GL_顶点_数组);
}
作废显示(作废)
{
int宽度、高度;
宽度=glutGet(GLUT\u窗口\u宽度);
高度=glutGet(GLUT\u窗口\u高度);
glClearColor(0.3,0.3,0.3,1.0);
glClear(GLU颜色缓冲位);
glViewport(0,0,宽度,高度);
glMatrixMode(GL_投影);
glLoadIdentity();
格洛托(0,宽度,0,高度,-1,1);
glMatrixMode(GLU模型视图);
glLoadIdentity();
/*鼠标在窗口顶部*/
glTranslatef(鼠标x,高度-鼠标y,0);
glColor4f(1.0,0.0,0.0,1.0);
画方(16);
glutSwapBuffers();
}
无效鼠标移动(整数x,整数y)
{
鼠标x=x;
鼠标_y=y;
再发现();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
创建窗口(“鼠标运动”);
glutDisplayFunc(显示器);
glutMotionFunc(鼠标运动);
GLUT被动情绪功能(鼠标运动);
鼠标x=鼠标y=0;
glutMainLoop();
}

OpenGL不处理用户输入。Nicol Bolas:没有什么可以发布的,因为我不知道应该写什么代码,我只知道只有当其中一个按钮被释放时,MouseFunc才会退出。OpenGL不处理用户输入。OpenGL只画东西。Nicol Bolas:因为我不知道应该写什么代码,所以没有什么可发布的,我只知道只有当其中一个按钮被释放时,MouseFunc才会退出。GlutPassibileMotionFunc不处理“OnMouseClick”事件,只处理x,ychangings@igalk:然后看看glutMotionFunc,在同一手册页中描述。使用事件处理函数更新变量并注册一个空闲函数,该函数将这些变量的值处理为绘制下一帧的状态,然后调用GLUTPOSTREDIDISPLAY。我不太确定我是否在跟踪你,你能详细说明一下吗?@igalk:请看我的代码示例,它会在鼠标指针后绘制一个红方块,无论您是否按下按钮。留给读者的练习:如果按下按钮,则将方形颜色更改为绿色。谢谢DatenWalf,我可以知道按下了哪个鼠标按钮吗?left还是right?GlutPassibileMotionFunc不处理“OnMouseClick”事件,只处理x,ychangings@igalk:然后查看同一手册页中描述的glutMotionFunc。使用事件处理函数更新变量并注册一个空闲函数,该函数将这些变量的值处理为绘制下一帧的状态,然后调用GLUTPOSTREDIDISPLAY。我不太确定我是否在跟踪你,你能详细说明一下吗?@igalk:请看我的代码示例,它会在鼠标指针后绘制一个红方块,无论您是否按下按钮。留给读者的练习:如果按下按钮,则将方形颜色更改为绿色。谢谢DatenWalf,我可以知道按下了哪个鼠标按钮吗?左边还是右边?