OpenGL framebuffer可调整大小的纹理

时间:2014-09-24 08:42:58

标签: c++ opengl cg

我在帧缓冲区中使用单色渲染

glGenFramebuffersEXT(1, &frontFramebufferId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frontFramebufferId);

glGenTextures(1, &frontTextureId);
glBindTexture(GL_TEXTURE_2D, frontTextureId);
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);
glBindTexture(GL_TEXTURE_2D, frontTextureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, frameStride, frameHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frontFramebufferId);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frontTextureId, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

当我调整窗口大小时,它会给我黑色。 调整大小功能:

glViewport(0, 0, frameStride, frameHeight);
glBindTexture(GL_TEXTURE_2D, frontTextureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, frameStride, frameHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frontFramebufferId);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frontTextureId, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

有必要在resize事件中使用glFramebufferTexture2DEXT函数吗?或者问题是什么?我正在使用Nvidia的Cg框架。

0 个答案:

没有答案