Jump to content
  • Advertisement
Sign in to follow this  
glmisscelan

FBO & RTT problem

This topic is 3938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im having some problems trying to render my scene to a texture. Here is my initialization code
    glGenTextures(1, &textura_fbo);
    glBindTexture(GL_TEXTURE_2D, textura_fbo);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w_size, h_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

    glGenRenderbuffersEXT(1, &depthbuffer);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);

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

     //definmos nuestro renderbuffer
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, w_size, h_size);

     //añadimos el renderbuffer al frambuffer
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer);

    //añadimos una textura
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textura_fbo, 0);
    //glBindTexture(GL_TEXTURE_2D, 0);
    //comprobamos si hay errores
    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);


I check the status and im not getting any errors. Here ara my binding and unbinding fbo code
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer);
    //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textura_fbo, 0);
    glPushAttrib(GL_VIEWPORT_BIT);
    glViewport(0, 0, w_size, h_size);


    glPopAttrib();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);


And the render texture code
    glBindTexture(GL_TEXTURE_2D, textura_fbo);

    // Set Flags
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glPushMatrix(); // Store The Projection Matrix

    // Change to orthogonal projection to do a texture blitter to the screen
    glLoadIdentity(); // Reset The Projection Matrix
    glOrtho(0,0,0,0,0,2000); // Set Up An Ortho Screen

    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glPushMatrix(); // Store The Modelview Matrix
    glLoadIdentity(); // Reset The Modelview Matrix

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f( 1.0f,  1.0f, 0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-1.0f,  1.0f, 0.0f);

    glEnd();

    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glPopMatrix(); // Restore The Old Projection Matrix

    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glPopMatrix(); // Restore The Old Projection Matrix*/


Now my problem is if i coment this line on init fbos procedure:
 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer);


i can see my scene without depth testing, but with it i see a black screen. Any idea? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I can't understand you're even seeing something, there's something really wrong with this line :

glOrtho(0,0,0,0,0,2000);

You're creating an orthographic projection as a 0-sized rectangle. If is ever does something, I could only expect it to show the single pixel located at (0, 0). Also, you're drawing your quad at z-depth 0, when your orthographic projection ranges from (0 to 2000), it's risky. If I was you, I'd change this line for :

glOrtho(0, 1, 0, 1, -1, 1);

Maybe your thing works, but I wouldn't bet on it.

Share this post


Link to post
Share on other sites
Yes, it was a mistake.

The FBO initialization procedure didnt give me any error, so i suspose that it moust be on render texture procedure, and thats why i started playing with glortho and gluperspective values. that mistake was one of this.

I continue playing with this but im not get it working when i set the glFramebufferRenderbufferEXT.

Thanks for your answer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!