现在由于某种原因,其中一个面不会渲染.我检查了椎体(首先在纸上绘制)并且看起来是正确的.如果我更改着色器以绘制线环,则会发现它会渲染.但是它不会呈现三角形.有人可以解释为什么吗
voID setupRC(){ glClearcolor(0.0f,0.0f,1.0f); shaderManager.InitializeStockShaders(); M3DVector3f vVerts1[] = {-0.5f,-0.5f,0.5f,-0.5f}; M3DVector3f vVerts2[] = {-0.5f,0.5f}; M3DVector3f vVerts3[] = {-0.5f,0.5f}; M3DVector3f vVerts4[] = {0.5f,-0.5f}; triangleBatch1.Begin(GL_liNE_LOOP,3); triangleBatch1.copyVertexData3f(vVerts1); triangleBatch1.End(); triangleBatch2.Begin(GL_TRIANGLES,3); triangleBatch2.copyVertexData3f(vVerts2); triangleBatch2.End(); triangleBatch3.Begin(GL_TRIANGLES,3); triangleBatch3.copyVertexData3f(vVerts3); triangleBatch3.End(); triangleBatch4.Begin(GL_TRIANGLES,3); triangleBatch4.copyVertexData3f(vVerts4); triangleBatch4.End(); glEnable(GL_CulL_FACE);}float rot = 1;voID renderScene(){ glClear(GL_color_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[] = {1.0f,0.5f}; GLfloat vBlue[] = {0.0f,1.0f,0.5f}; GLfloat vGreen[] = {0.0f,0.5f}; GLfloat vWhite[] = {1.0f,0.5f}; M3DMatrix44f transformMatrix; if (rot >= 360) rot = 0; else rot = rot + 1; m3dRotationMatrix44(transformMatrix,m3dDegToRad(rot),0.0f); shaderManager.UseStockShader(GLT_SHADER_FLAT,transformMatrix,vRed); triangleBatch1.Draw(); shaderManager.UseStockShader(GLT_SHADER_FLAT,vBlue); triangleBatch2.Draw(); shaderManager.UseStockShader(GLT_SHADER_FLAT,vGreen); triangleBatch3.Draw(); shaderManager.UseStockShader(GLT_SHADER_FLAT,vWhite); triangleBatch4.Draw(); glutSwapBuffers(); glutPostRedisplay(); Sleep(10);}解决方法 您很可能按顺时针顺序为未显示的三角形定义顶点,并按逆时针顺序(通常为默认值)定义顶点.顺时针缠绕基本上创建了一个向内的法线,因此当启用剔除时,OpenGL不会费心去渲染它.
检查这个的最简单方法是设置glCullFace(GL_FRONT) – 应该切换它,这样你就可以看到缺少的三角形而不再看到其他三个.
总结以上是内存溢出为你收集整理的c – 开始学习OpenGL,需要帮助解决这个问题全部内容,希望文章能够帮你解决c – 开始学习OpenGL,需要帮助解决这个问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)