Original Post
I've been trying but nothing seemed to work out, it's got to be an easy fix, but I don't see it.
Draw code:
Init code (both functions are called prior to draw):
The FBO is complete, no error message. glGetError() returns 0.
The FBO is black, but it should be green. If I remove the framebuffer bindings (and the code afterwards) it indeed shows green. But somehow the scene_texture remains empty.
Drawing something else but scene_texture (other texture) works, so scene_texture is simply black.
I hate dumping code like this, but I really don't see the problem...
Thanks!
Draw code:
void draw()
{
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, scene_fbo);
glViewport (0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, cast(float) width / height, nearPlane, farPlane);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, cast(float) width / height, nearPlane, farPlane);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, scene_texture);
glBegin(GL_QUADS);
glTexCoord2d(0.0, 0.0);
glVertex3d(-2.0, -2.0, -2.0);
glTexCoord2d(texture_scale, 0.0);
glVertex3d(2.0, -2.0, -2.0);
glTexCoord2d(texture_scale, texture_scale);
glVertex3d(2.0, 2.0, -2.0);
glTexCoord2d(0.0, texture_scale);
glVertex3d(-2.0, 2.0, -2.0);
glEnd();
SDL_GL_SwapBuffers();
}Init code (both functions are called prior to draw):
GLuint scene_texture, scene_rbo, scene_fbo;
void init_opengl()
{
glViewport (0, 0, width, height);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
}
void init_fbo()
{
glGenTextures(1, &scene_texture);
glBindTexture(GL_TEXTURE_2D, scene_texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
glBindTexture(GL_TEXTURE_2D, 0);
// create a renderbuffer object to store depth info
glGenRenderbuffersEXT(1, &scene_rbo);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, scene_rbo);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
// create a framebuffer object
glGenFramebuffersEXT(1, &scene_fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, scene_fbo);
// attach the texture to FBO color attachment point
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, scene_texture, 0);
// attach the renderbuffer to depth attachment point
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, scene_rbo);
// check FBO status
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
writeln("FBO error");
}
// switch back to window-system-provided framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}The FBO is complete, no error message. glGetError() returns 0.
The FBO is black, but it should be green. If I remove the framebuffer bindings (and the code afterwards) it indeed shows green. But somehow the scene_texture remains empty.
Drawing something else but scene_texture (other texture) works, so scene_texture is simply black.
I hate dumping code like this, but I really don't see the problem...
Thanks!