我正在制作一个简单的像素引擎(类似于Minecraft),目前正处于消除遮挡面以获得宝贵帧率的阶段。我的OpenGL经验不是很丰富,也不太理解glColorMask函数的原理。
以下是我的代码:
// new and shiny
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// this one goes without saying
glEnable(GL_DEPTH_TEST);
// I want to see my code working, so fill the mask
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// fill the z-buffer, or whatever
glDepthFunc(GL_LESS);
glColorMask(0,0,0,0);
glDepthMask(GL_TRUE);
// do a first draw pass
world_display();
// now only show lines, so I can see the occluded lines do not display
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// I guess the error is somewhere here
glDepthFunc(GL_LEQUAL);
glColorMask(1,1,1,1);
glDepthMask(GL_FALSE);
// do a second draw pass for the real rendering
world_display();
这个方法有些作用,但是一旦我改变相机位置,世界就开始逐渐消失了,我看到的线条越来越少,直到完全没有。
world_display()
函数是否已经使用了顶点数组(VAs)或者顶点缓冲对象(VBOs)来提交几何图形呢? - genpfault