Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.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/0/windows/17.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
C++ 在OpenGL上使用点绘制的意外gluLookAt行为_C++_Windows_Opengl_Glu - Fatal编程技术网

C++ 在OpenGL上使用点绘制的意外gluLookAt行为

C++ 在OpenGL上使用点绘制的意外gluLookAt行为,c++,windows,opengl,glu,C++,Windows,Opengl,Glu,我目前正在处理读取3D obj文件的软件的打印循环。 我已将读取的obj文件存储在变量tie中。此变量包含一个OpenGL列表。我的目标是能够使用键盘在读取对象周围移动。键盘读取正确执行(我可以从日志中看到) 问题 当我编译下面的代码循环时,gluLookAt会正确运行,我可以通过更改参数值来移动对象 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BI

我目前正在处理读取3D obj文件的软件的打印循环。 我已将读取的obj文件存储在变量
tie
中。此变量包含一个OpenGL列表。我的目标是能够使用键盘在读取对象周围移动。键盘读取正确执行(我可以从日志中看到)

问题 当我编译下面的代码循环时,
gluLookAt
会正确运行,我可以通过更改参数值来移动对象

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            light();
            gluPerspective (60.0, 250/(float)250, 0.1, 500.0);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            gluLookAt(eyeX,eyeY,eyeZ,eyeX+directionX,eyeY+directionY,eyeZ+directionZ,upX,upY,upZ);

            glPushMatrix();
            glRotated(45,0,0,1);
            glTranslated(0,0,50);
            glBindTexture(GL_TEXTURE_2D,texture1);
            //glCallList(xwing); //ICI
            glEnd();
            glPopMatrix();
                glColor3d(1,1,1);
                glDisable(GL_LIGHTING);
                glBindTexture(GL_TEXTURE_2D,texture2);
                GLUquadric* params = gluNewQuadric();
                gluQuadricDrawStyle(params,GLU_FILL);
                gluQuadricTexture(params,GL_TRUE);
                gluSphere(params,100,20,20);
                gluDeleteQuadric(params);
                glEnable(GL_LIGHTING);
            glBindTexture(GL_TEXTURE_2D,texture1);
            glCallList(tie); //ICI
            glPointSize(5.0);
            glBegin(GL_POINTS);
                glColor3f(1.0f,0.0f,0.0f);
                glVertex3f(-1.0f,0.0f,0.0f);
            glEnd();


            SwapBuffers(hDC);
        //} //else
        Sleep(1);
但当我评论这四行时:

glBegin(GL_POINTS);
                glColor3f(1.0f,0.0f,0.0f);
                glVertex3f(-1.0f,0.0f,0.0f);
glEnd();
我的物体不再移动了。好像gluLookAt没有成功执行。 你知道为什么会这样吗。我在代码中忘记了什么吗?

并定义了定义一个基本体或一组类似基本体的顶点。您必须确保每个后面都有一个。
这意味着,如果包含,那么它也应该包含。我强烈建议这样做。另一种可能是在以下情况下手动执行:


和用于推送矩阵并从矩阵堆栈中弹出矩阵。如果要将模型矩阵添加到视图矩阵,则必须执行以下步骤

  • 按下视图矩阵。这将在堆栈上推送视图矩阵的副本
  • 将模型矩阵添加到当前视图矩阵(
    glRotated
    glTranslated
    ,…)
  • 画模型。(,
    gluSphere
    ,…)
  • 恢复原始视图矩阵()

以如下方式调整代码:

// set up view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,eyeX+directionX,eyeY+directionY,eyeZ+directionZ,upX,upY,upZ);

// save view matrix
glPushMatrix();

// add model matrix
glRotated(45,0,0,1);
glTranslated(0,0,50);

// do the drawing
glColor3d(1,1,1);
glDisable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D,texture2);
GLUquadric* params = gluNewQuadric();
gluQuadricDrawStyle(params,GLU_FILL);
gluQuadricTexture(params,GL_TRUE);
gluSphere(params,100,20,20);
gluDeleteQuadric(params);
glEnable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D,texture1);
glCallList(tie); 
glEnd(); // <-- maybe this could be done in "tie"

// restore the view matrix
glPopMatrix();
//设置视图矩阵
glMatrixMode(GLU模型视图);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,eyeX+方向x,eyeY+方向y,eyeZ+方向z,upX,upY,upZ);
//保存视图矩阵
glPushMatrix();
//添加模型矩阵
(45,0,0,1);
gl(0,0,50);
//画画
glColor3d(1,1,1);
glDisable(GLU照明);
glBindTexture(GL_TEXTURE_2D,texture2);
GLUquadric*params=gluNewQuadric();
GLU样式(参数,GLU_填充);
GluQuadractexture(参数,GL_-TRUE);
gluSphere(参数,100,20,20);
二次曲面(参数);
glEnable(德国劳埃德大学照明);
glBindTexture(GL_TEXTURE_2D,texture1);
电话名单(tie);

格伦德();//非常感谢。实际上,在我的列表创建函数中,我首先使用了
glEndList
,然后使用了
glEnd
。因此,
glEnd
在我的循环中没有被调用。非常感谢。
// set up view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,eyeX+directionX,eyeY+directionY,eyeZ+directionZ,upX,upY,upZ);

// save view matrix
glPushMatrix();

// add model matrix
glRotated(45,0,0,1);
glTranslated(0,0,50);

// do the drawing
glColor3d(1,1,1);
glDisable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D,texture2);
GLUquadric* params = gluNewQuadric();
gluQuadricDrawStyle(params,GLU_FILL);
gluQuadricTexture(params,GL_TRUE);
gluSphere(params,100,20,20);
gluDeleteQuadric(params);
glEnable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D,texture1);
glCallList(tie); 
glEnd(); // <-- maybe this could be done in "tie"

// restore the view matrix
glPopMatrix();