Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenGL Glut拾取不处理命中_Opengl_Glut_Picking - Fatal编程技术网

OpenGL Glut拾取不处理命中

OpenGL Glut拾取不处理命中,opengl,glut,picking,Opengl,Glut,Picking,我不明白为什么我在点击任何东西时总是得到0次点击。我已经让主机器人工作了,并且它对键盘命令的响应非常好,但由于某种原因,我似乎无法让它记录成功。一直在尝试遵循本教程: 完整代码如下: inthandlepicking(intx,inty) { 整数命中率; 闪烁视口[4]; glSelectBuffer(BUFSIZE,selectBuf); glRenderMode(GL_选择); glMatrixMode(GL_投影); glPushMatrix(); glLoadIdentity(); g

我不明白为什么我在点击任何东西时总是得到0次点击。我已经让主机器人工作了,并且它对键盘命令的响应非常好,但由于某种原因,我似乎无法让它记录成功。
一直在尝试遵循本教程:
完整代码如下:

inthandlepicking(intx,inty)
{
整数命中率;
闪烁视口[4];
glSelectBuffer(BUFSIZE,selectBuf);
glRenderMode(GL_选择);
glMatrixMode(GL_投影);
glPushMatrix();
glLoadIdentity();
glGetIntegerv(GL_视口,视口);
选择矩阵(x,视区[3]-y,5,5,视区);
glMatrixMode(GLU模型视图);
glInitNames();
//恢复原始投影矩阵
glMatrixMode(GL_投影);
glPopMatrix();
glMatrixMode(GLU模型视图);
glFlush();
//返回到正常渲染模式
hits=glRenderMode(GLU渲染);

std::cout看起来您没有设置视图矩阵(glortho,glupperspective)或渲染要拾取的机器人。请看下面的操作。我相信它会有所帮助,因为它是类的一部分

GLvoid CGame::Selection(GLvoid)
{
    GLuint  buffer[512];
    GLint   hits;
    GLint   viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(512, buffer);
    (GLvoid) glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y-4), 8.0f, 8.0f, viewport);
    gluPerspective(70.0f,(GLfloat)width/(GLfloat)height,0.001f,100.0f);
    glMatrixMode(GL_MODELVIEW);

    renderTargetAnswers(); //YOUR ROBOT() SHOULD GO HERE
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    hits=glRenderMode(GL_RENDER);
    if (hits>0)
    {
        score+=1;
        int choose = buffer[3];
        int depth = buffer[1];
        for (int loop = 1; loop<hits;loop++)
        {
            if (buffer[loop*4+1] < GLuint(depth))
            {
                choose = buffer[loop*4+3];
                depth = buffer[loop*4+1];
            }       
        }
        if (!targetanswers[choose].hit)
        {
            targetanswers[choose].hit=GL_TRUE;
        }
    }
}
GLvoid CGame::Selection(GLvoid)
{
胶合缓冲区[512];
闪烁的点击;
闪烁视口[4];
glGetIntegerv(GL_视口,视口);
glSelectBuffer(512,buffer);
(GLvoid)glRenderMode(GL_选择);
glInitNames();
glPushName(0);
glMatrixMode(GL_投影);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble)鼠标_x,(GLdouble)(视口[3]-鼠标_y-4),8.0f,8.0f,视口);
玻璃液位(70.0f,(玻璃液位)宽度/(玻璃液位)高度,0.001f,100.0f);
glMatrixMode(GLU模型视图);
renderTargetAnswers();//你的机器人()应该在这里
glMatrixMode(GL_投影);
glPopMatrix();
glMatrixMode(GLU模型视图);
hits=glRenderMode(GLU渲染);
如果(点击次数>0)
{
分数+=1;
int choose=buffer[3];
int深度=缓冲区[1];
for(int循环=1;循环
GLvoid CGame::Selection(GLvoid)
{
    GLuint  buffer[512];
    GLint   hits;
    GLint   viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(512, buffer);
    (GLvoid) glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y-4), 8.0f, 8.0f, viewport);
    gluPerspective(70.0f,(GLfloat)width/(GLfloat)height,0.001f,100.0f);
    glMatrixMode(GL_MODELVIEW);

    renderTargetAnswers(); //YOUR ROBOT() SHOULD GO HERE
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    hits=glRenderMode(GL_RENDER);
    if (hits>0)
    {
        score+=1;
        int choose = buffer[3];
        int depth = buffer[1];
        for (int loop = 1; loop<hits;loop++)
        {
            if (buffer[loop*4+1] < GLuint(depth))
            {
                choose = buffer[loop*4+3];
                depth = buffer[loop*4+1];
            }       
        }
        if (!targetanswers[choose].hit)
        {
            targetanswers[choose].hit=GL_TRUE;
        }
    }
}