Jump to content
  • Advertisement
Sign in to follow this  
htz92127

The question of FBO

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

I want to render some thing to the RenderTarget, then render the RenderTarget on the screen. But the question is that, the result of RenderTarget is not accurate right. It have been stretched.
I use this code to change the RenderTarget:


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,mCurrentTarget.nFboID);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, mCurrentTarget.nWidth, mCurrentTarget.nHeight);



Is there something wrong?

Share this post


Link to post
Share on other sites
Advertisement

Would you mind showing us your texture dimensions and exactly how you output it to the screen?

Sure, but my code is in my office computer, I am at home now. I will paste it out tomorrow.
And there is another question:
I call glClearColor() function after glBindFramebufferEXT to clear the BackColor of the fbo, But the BackColor of normal buffer is also be changed. Why such a situation?

Share this post


Link to post
Share on other sites

I call glClearColor() function after glBindFramebufferEXT to clear the BackColor of the fbo, But the BackColor of normal buffer is also be changed. Why such a situation?


[font=monospace][size=2]GL_COLOR_CLEAR_VALUE is a part of rendering context state. It is not tied to any specific buffer.[/font]

Share this post


Link to post
Share on other sites

[quote name='htz92127' timestamp='1311517678' post='4839594']
I call glClearColor() function after glBindFramebufferEXT to clear the BackColor of the fbo, But the BackColor of normal buffer is also be changed. Why such a situation?


[font="monospace"]GL_COLOR_CLEAR_VALUE is a part of rendering context state. It is not tied to any specific buffer.[/font]
[/quote]
Maybe there is some Ambiguity of my expression. I mean that:
[color="#1C2837"][font="CourierNew, monospace"] [/font]
[color="#1C2837"][font="CourierNew, monospace"] [/font]
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,mCurrentTarget.nFboID);
glClearColor(1.0, 0, 0, 0);
glViewport(0,0, mCurrentTarget.nWidth, mCurrentTarget.nHeight);


This code should just change the backcolor of the FBO which id is nFboID, But the window's color(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)[size=2]) is also be changed to red. why?

Share this post


Link to post
Share on other sites
[font="monospace"][color="#1c2837"]No. This code, among other things, should change context-global background color value to red.[/font]

Share this post


Link to post
Share on other sites
I got that, the function glClearColor just change the state of the gl. The glClear do the work of clear buffer. I misunderstood.

Share this post


Link to post
Share on other sites

You are getting results with FBOs? I just posted a question about this. My texture doesn't display when drawing the texture to a sprite in my sprite batch: http://www.gamedev.n...objects-opengl/. Everything checks out fine, but I get nothing.

Yes, I got a results, But the viewport is not right.

The code of create fbo:


u32 nTexID;
glGenTextures(1, &nTexID);
glBindTexture(GL_TEXTURE_2D, nTexID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nWidth, nHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

u32 fboID;
glGenFramebuffersEXT(1,&fboID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fboID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, nTexID, 0);
u32 buffers[] = {GL_COLOR_ATTACHMENT0_EXT};
glDrawBuffers(1, buffers);

GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

if (GL_FRAMEBUFFER_COMPLETE_EXT != status)
{
return ImageRef::Null();
}

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);


The code of draw fbo textrue:





glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mCurrentTarget.nID);
glClearColor(1, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, mCurrentTarget.nWidth, mCurrentTarget.nHeight);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex->GetID());

glColor4ub(color.R, color.G, color.B, color.A);
glBegin(GL_QUADS);

glTexCoord2f(0.0f, 1.0f);
glVertex2i(x1, y1);

glTexCoord2f(1.0f, 1.0f);
glVertex2i(x2, y1);

glTexCoord2f(1.0f, 0.0f);
glVertex2i(x2, y2);

glTexCoord2f(0.0f, 0.0f);
glVertex2i(x1, y2);

glEnd();



Is there some thing wrong?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!