我正在尝试进行屏幕外渲染然后blit到屏幕(默认FB),但我看到的只是一个黑色的窗口。我只是将屏幕外纹理清除为绿色并将其复制到屏幕Framebuffer。这是代码:
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGenFramebuffers(1, &renderTexture);
glBindFramebuffer(GL_FRAMEBUFFER, renderTexture);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
std::cout <<"\n Error in framebuffer";
}
GLint val = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(val != GL_FRAMEBUFFER_COMPLETE)
{
std::cout <<"\n Error in framebuffer : 2";
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f,1.0f,0.0f,0.0f);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, renderTexture);
glBlitFramebuffer(0, 0, 128, 128, 0, 0, 128, 128, GL_COLOR_BUFFER_BIT, GL_NEAREST);
答案 0 :(得分:1)
在清除之后将清除颜色设置为绿色,以便将其清除为原始的清晰颜色,除非您将其设置为其他地方为黑色。清除帧缓冲区之前,需要设置清晰的颜色。代码应该是:
glClearColor(0.0f,1.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
请参阅glClearColor的说明以供参考:https://www.opengl.org/sdk/docs/man/html/glClearColor.xhtml。