8
我正在將我的場景渲染到紋理。這工作正常,但深度測試不起作用。如果渲染到離屏紋理,我如何啓用深度測試?我使用framebuffer類http://www.opengl.org/news/comments/framebuffer_object_fbo_c_class_available_with_example_application/如何在渲染到離屏緩衝區然後渲染到紋理時使用深度測試
glGetIntegerv(GL_DRAW_BUFFER, &drawBuffer);
frameBuffer->Bind();
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
rAngle += 0.3f;
glUseProgram(0);
drawSpinningTeapot();
FramebufferObject::Disable();
glDrawBuffer(drawBuffer);
glViewport(0, 0, WINDOW_WIDTH,WINDOW_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(g_program);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,tex1);
texSampler = glGetUniformLocation(g_program,"texture");
glUniform1f(texSampler, 0);
glActiveTexture(GL_TEXTURE0);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
glTexCoord2f(1, 0); glVertex3f(1, -1, -0.5f);
glTexCoord2f(1, 1); glVertex3f(1, 1, -0.5f);
glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f);
}
glEnd();
glDisable(GL_TEXTURE_2D);
我一直在尋找所有的地方對於這一點,謝謝! – axel22 2012-09-27 18:44:00
我想知道*爲什麼*完全應該這樣做。 – 2013-03-20 13:57:55