OpenGL ES 2.0を使用してテクスチャにレンダリングしようとしていますが、機能しないようです。
これが私が進める方法です:
struct RenderTexture
{
GLuint framebuffer;
GLuint tex;
GLint old_fbo;
RenderTexture(GLuint width, GLuint height)
{
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);
glGenFramebuffers(1, &framebuffer);
glGenTextures(1, &tex);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
tex, 0);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
cout << status << endl; // this is not called
}
glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
}
void begin()
{
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
}
void end()
{
glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
}
};
しかし、その上に描画して、結果のテクスチャを使用しようとすると、テクスチャは完全に黒く描画されます。
描画コードをとでラップしないrender_tex->begin();
とrender_tex->end();
、すべてが正しく描画され、問題は上記のコードに限定されていると思います。