ok so after many sleepless nights (and no replies here
)
i finally found out how to do it
void buildFramebuffer()
{
renderTarget = new Texture3D(GL_RGB, GL_RGB8, GL_UNSIGNED_BYTE, GL_LINEAR, GL_CLAMP_TO_EDGE, 100,100,100,NULL);
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, renderTarget->getId(), 0, 0);
GLenum buffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, buffers);
glReadBuffer(GL_NONE);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
printf("Framebuffer status: %s\n", status == GL_FRAMEBUFFER_COMPLETE?"OK":"ERROR");
}
void fillTarget()
{
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,100,100);
for(int i = 0; i < 100; i++)
{
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderTarget->getId(), 0, i);
glClearColor(1.0f,(1.0f/100.0f)*((float)i),0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glColor3f(0.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,0.0f,0.0f);
glVertex3f( 0.0f,1.0f,0.0f);
glVertex3f( 1.0f,0.0f,0.0f);
glEnd();
}
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void draw()
{
fillTarget();
glClearColor(0.0f,0.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_3D);
renderTarget->bind();
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord3f(0.0f,0.0f,1.0f); glVertex3f(-1.0f, 1.0f,0.0f);
glTexCoord3f(0.0f,1.0f,1.0f); glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord3f(1.0f,1.0f,1.0f); glVertex3f( 1.0f,-1.0f,0.0f);
glTexCoord3f(1.0f,0.0f,1.0f); glVertex3f( 1.0f, 1.0f,0.0f);
glEnd();
Texture3D::unbind();
SDL_GL_SwapBuffers();
}
just posting this here for the people facing similar problems
this code should render a blue background with a yellow quad in the center with a turquoise triangle in it
(the quad is yellow because the texcoords Z is 1 if it were 0 the quad would be red)
however if someone finds anything wrong with my code feel free to point any mistakes out (apart from every 2nd function call being deprecated)