The question of FBO

Started by
11 comments, last by htz92127 12 years, 8 months ago
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?
Advertisement
Would you mind showing us your texture dimensions and exactly how you output it to the screen?
WBW, capricorn

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?

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]
WBW, capricorn

[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?
[font="monospace"][color="#1c2837"]No. This code, among other things, should change context-global background color value to red.[/font]
WBW, capricorn
I got that, the function glClearColor just change the state of the gl. The glClear do the work of clear buffer. I misunderstood.
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.net/topic/607000-framebuffer-objects-opengl/. Everything checks out fine, but I get nothing.

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?
Are you setting up your projection matrix when rendering to that FBO?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement