Jump to content
  • Advertisement
Sign in to follow this  
furrymaster

[OGL] FBO problem

This topic is 3008 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

Hello i have problem with rendering into FBO. Here is code:

FBO::FBO(bool depthOnly, int vx, int vy, int vwidth, int vheight)
{

vX=vx;
vY=vy;
if(vwidth!=vheight)
{
vwidth=max(vwidth,vheight);
vheight=vwidth;
}
vWidth=vwidth;
vHeight=vheight;
if(!fboInitialized)
initFBO();
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vwidth, vheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);

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

glGenRenderbuffersEXT(1, &rboId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, vwidth, vheight);

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

if(!depthOnly)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId);
string error;
if(StrToInt(error=getGLError())!=0)
{
PrintError(error,"FBO_GL error");
}
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status!=GL_FRAMEBUFFER_COMPLETE_EXT)
{
PrintError(IntToStr(status),"FBO error");
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
FBO::~FBO()
{
glDeleteFramebuffersEXT(1, &fboId);
glDeleteRenderbuffersEXT(1, &rboId);
glDeleteTextures(1, &textureId);
}
void FBO::startRenderInto(float r, float g, float b,float a)
{
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(vX, vY, vWidth, vHeight);
glMatrixMode(GL_MODELVIEW);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

}
void FBO::stopRenderInto()
{

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
/* glBindTexture(GL_TEXTURE_2D, textureId);
glGenerateMipmapEXT(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
*/
glPopAttrib();

}
void FBO::activate()
{
glBindTexture(GL_TEXTURE_2D, textureId);
}
void FBO::deactivate()
{
glBindTexture(GL_TEXTURE_2D, 0);
}

I`m rendering this ball into buffer:


And:
with this config of texture:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);//with TO_EDGE i have full white quad
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

Texture is like that:


and without that code I have texture like this:

As you can see now is nearly ok, but we can see duplicated texture many times and FPS is changing from 400 to 50<->30

What am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Most of it seems ok, but I'm not sure about the mipmapping when it comes to render buffers, is it supported? Try setting the texture filter to Linear or Nearest for min and mag for the framebuffer texture, and remove that generate mipmap hint.

Share this post


Link to post
Share on other sites
Quote:
Most of it seems ok, but I'm not sure about the mipmapping when it comes to render buffers, is it supported?

Yes, it is and with generate mipmaping its the same.

About near and linear: i tried many combinations and I see good rendered ball only when I hint
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

But then FPS is 50-30 and texture is duplicated(as in last picture)

EDIT:
when i use
glBindTexture(GL_TEXTURE_2D, textureId);

glGenerateMipmapEXT(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, 0);

and i DON`T use:
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

I`m getting error 36061(GL_FRAMEBUFFER_UNSUPPORTED_EXT). But only there

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!