因为glOrtho改变,我的鼠标回调不起作用。为什么?

问题描述 投票:0回答:1

如果glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0)然后我的代码工作。但是,如果我改为glOrtho(0.0, 800.0, 0.0, 600.0, -1.0, 1.0),那么我的代码就无效了。也许鼠标回调不起作用。改变glOrtho是努力鼠标回调?我不知道问题是什么。

这是我的代码:

GLfloat myVertices[10][2];          
GLfloat Width = 800.0;      
GLfloat Height = 600.0;
GLint count = 0;

void Mouse(int button, int state, GLint x, GLint y)
{
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        myVertices[count][0] = x / Width;
        myVertices[count][1] = (Height - y) / Height;
        count++;         

        drawScene();      
    }
}

GLvoid drawScene()                                  
{
    GLint index;

    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1, 0, 0); 
    glPointSize(3.0f); 
    glEnableClientState(GL_VERTEX_ARRAY);     
    if (count > 0)
    {
        for (index = 0; index < count; index++)
        {
            glRectf(myVertices[index][0], myVertices[index][1], myVertices[index][0] + 0.01, myVertices[index][1] + 0.05);
            //glRectf(myVertices[index][0], myVertices[index][1], myVertices[index][0]+50, myVertices[index][1]+50);
        }
    }

    glFlush();                              
}
c opengl glut
1个回答
0
投票

你的鼠标回调像以前一样工作。你的坐标没有多大意义:

    myVertices[count][0] = x / Width;
    myVertices[count][1] = (Height - y) / Height;

这将导致[0,1]中的值,这意味着当您在设置时应用像素完美的正投影时,它们将全部位于屏幕的左下角像素中。

© www.soinside.com 2019 - 2024. All rights reserved.