简体   繁体   English

将深度缓冲区渲染到纹理的管道可能有什么问题?

[英]What might be the issue with my pipeline to rendering the depth buffer to a texture?

The main steps for depth testing from my understanding: 1) enable depth testing and how we want to depth test 2) create the frame buffer object and make sure it has a depth attached to it 3) bind our frame buffer object ( make sure to clear it before rendering ) 4) draw stuff 根据我的理解,深度测试的主要步骤是:1)启用深度测试以及我们要如何进行深度测试2)创建帧缓冲区对象并确保它具有附加的深度3)绑定我们的帧缓冲区对象(确保渲染之前将其清除)4)绘制东西

And that should be it no? 那应该不是吗? our frame buffer depth attachment should have depth data? 我们的帧缓冲区深度附件应该具有深度数据? But I always get straight 1's default depth clear color 但是我总是得到直线1的默认深度清除颜色

step 1: 第1步:

glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL );

step 2: 第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);

step 3: 步骤3:

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

//clear it
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

step 4: 第四步:

//draw things

Are these not the steps? 这些不是步骤吗?
Am i missing something? 我想念什么吗?
I've tried a few different tutorials. 我尝试了一些不同的教程。
I can't get any depth to render to a texture I keep getting straight 1's over and over. 我无法获得任何深度来渲染一遍又一遍的笔直纹理。

The framebuffer probably is not complete. 帧缓冲区可能不完整。 Try checking for completeness . 尝试检查完整性 Moreover your code was: 此外,您的代码是:

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

However, it should be (watch the RGB-RGBA): 但是,它应该是(观看RGB-RGBA):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM