1

据我了解,深度测试的主要步骤:1)启用深度测试以及我们希望如何进行深度测试 2)创建帧缓冲区对象并确保它具有附加的深度 3)绑定我们的帧缓冲区对象(确保在渲染之前清除它)4)绘制东西

那应该不是吗?我们的帧缓冲深度附件应该有深度数据吗?但我总是得到直 1 的默认深度清晰颜色

步骤1:

glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL );

第2步:

//create the frame buffer object
glGenFramebuffers(1, &m_uifboHandle);

// Initialize FBO
glBindFramebuffer(GL_FRAMEBUFFER, m_uifboHandle);

//create 2 texture handles 1 for diffuse, 1 for depth
unsigned int m_uiTextureHandle[2];
glGenTextures( 2, m_uiTextureHandle );

//create the diffuse texture
glBindTexture( GL_TEXTURE_2D, m_uiTextureHandle[0]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, uiWidth, uiHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_uiTextureHandle[0], 0); 

.

//create the depth buffer
glBindTexture(GL_TEXTURE_2D, m_uiTextureHandle[1]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, uiWidth, uiHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_uiTextureHandle[1], 0);

//go back to default binding
glBindFramebuffer(GL_FRAMEBUFFER, 0);

第 3 步:

//bind the frame buffer object
glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle );

//clear it
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

第4步:

//draw things

这些不是步骤吗?
我错过了什么吗?
我尝试了一些不同的教程。
我无法获得任何深度来渲染纹理,我一遍又一遍地获得直线 1。

4

1 回答 1

0

帧缓冲区可能不完整。尝试检查完整性。此外,您的代码是:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, uiWidth, uiHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

但是,它应该是(观看 RGB-RGBA):

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, uiWidth, uiHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
于 2014-09-06T12:06:38.237 回答