
以下代码是发生问题的代码的简单示例.它在同一个地方渲染出2个梯形,其中一个旋转.但旋转的一个总是显示在顶部,即使旋转时应该在第一个梯形后面.
我想我通过初始化OpenGL搞砸了一些东西.此外,当搜索stackoverflow时,我发现有人建议执行以下代码并查看输出的帖子.
int depth;glGetIntegerv(GL_DEPTH_BITS,&depth);printf("%i bits depth",depth); 好的输出是,0位深度,这是不好我猜:(
我正在使用glfw库在xCode上开发Mac
#include <GL/glfw.h>#include <stdlib.h>int main( voID ){ int running = GL_TRUE; if( !glfwInit() ) { exit( EXIT_FAILURE ); } // Open an OpenGL window if( !glfwOpenWindow( 640,480,GLFW_WINDOW )) { glfwTerminate(); exit( EXIT_FAILURE ); } glEnable(GL_DEPTH_TEST); float angle = 0; // Main loop while( running ) { double elapsedtime = glfwGetTime(); glfwSetTime(0); angle += 90 * elapsedtime; // OpenGL rendering goes here... glClear( GL_color_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode(GL_MODELVIEW); glLoadIDentity(); glPushmatrix(); //Save the transformations performed thus far glcolor3f(1.0f,1.0,0.0); glTranslatef(0.0f,0.0f,0.0f); //Move to the center of the trapezoID //glrotatef(angle,1.0f,0.0f); //Rotate about the y-axis glBegin(GL_QUADS); //TrapezoID glVertex3f(-0.7f,-0.5f,0.0f); glVertex3f(0.7f,0.0f); glVertex3f(0.4f,0.5f,0.0f); glVertex3f(-0.4f,0.0f); glEnd(); glPopMatrix(); glPushmatrix(); //Save the transformations performed thus far glcolor3f(1.0f,0.0,0.0f); //Move to the center of the trapezoID glrotatef(angle,0.0f); glEnd(); glPopMatrix(); //Undo the move to the center of the trapezoID glfwSwapBuffers(); // Check if ESC key was pressed or window was closed running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetwindowParam( GLFW_OPENED ); } // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS );}解决方法 if( !glfwOpenWindow( 640,GLFW_WINDOW ))
为什么你通过所有这些零?那些参数很重要. GLFW reference documentation (pdf)显示这些参数描述了颜色,深度和模板所需的位数.倒数第二个零是深度位的数量.你为帧缓冲要求了0位深度,这就是你得到的.
你不能责怪API做你所要求的;)
一个更合理的命令是:
if( !glfwOpenWindow( 640,8,24,GLFW_WINDOW ))
这为RGBA提供了8位,深度为24位,模板为8位.
总结以上是内存溢出为你收集整理的xcode – OpenGL深度问题全部内容,希望文章能够帮你解决xcode – OpenGL深度问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)