深度不能在FBO OpenGL上渲染球形纹理

时间:2015-01-31 18:37:59

标签: opengl geometry depth fbo depth-buffer

我想在FBO上渲染我的球形纹理,然后在球形环境移动的同时在屏幕上绘制它。

但似乎深度不起作用,因为我只能看到前面部分"球体。

以下是代码:

// Create RenderBuffer
glGenRenderbuffers(1, &rboA);
glBindRenderbuffer(GL_RENDERBUFFER, rboA);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT, widthFBO, heightFBO);
glBindRenderbuffer(GL_RENDERBUFFER,0);  // Unbind RenderBuffer

// Create FrameBuffer
glGenFramebuffers(1, &fboA);
glBindFramebuffer(GL_FRAMEBUFFER, fboA);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboA);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
    GL_TEXTURE_2D, LDRtex->getID(), 0); 
glBindFramebuffer(GL_FRAMEBUFFER, 0);

使用其他纹理作为源(HDRtex)在FBO(LDRtex)上渲染纹理:

glBindFramebuffer(GL_FRAMEBUFFER, fboA);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glActiveTexture(GL_TEXTURE0); HDRTex->bind();   // Source tex

Shad->bind();
    Shad->setUniformValue4f("MVP", glm::value_ptr(MVP));
    sphere->draw(Shad);
Shad->unbind();
glActiveTexture(GL_TEXTURE0); HDRTex->unbind(); 
glBindFramebuffer(GL_FRAMEBUFFER, 0);

片段着色器:

#version 420
layout(binding=0) uniform sampler2D hdrSampler;      average of luminance
smooth in vec2 vTexCoord;           // texCoords from sample output
layout(location=0) out vec4 color;  // output


void main(){
   color = texture(hdrSampler, vTexCoord);
}

渲染代码:

// Reset conditions
glBindFramebuffer(GL_FRAMEBUFFER, 0);   
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);                    
glUseProgram(0);                                                                        
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     

// Main FB rendering

renderonFBO();
Shad->bind();
    Shad->setUniformValue4f("MVP", glm::value_ptr(MVP));
    LDRtex->bind();
    sphere->draw(Shad);
    LDRtex->unbind(); yrot += 0.5; // yrot is ycoord, to move sphere
Shad->unbind();

这是图形序列:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

0 个答案:

没有答案