PDA

View Full Version : A strange problem about FBO



spring
01-02-2007, 07:20 PM
here is my code :
GLuint ATTACHMENT_ARRAY[] = {GL_COLOR_ATTACHMENT0_EXT,GL_COLOR_ATTACHMENT1_EXT ,GL_COLOR_ATTACHMENT2_EXT,GL_COLOR_ATTACHMENT3_EXT ,GL_COLOR_ATTACHMENT4_EXT,GL_COLOR_ATTACHMENT5_EXT ,GL_COLOR_ATTACHMENT6_EXT,GL_COLOR_ATTACHMENT7_EXT ,GL_COLOR_ATTACHMENT8_EXT,GL_COLOR_ATTACHMENT9_EXT };

--------------------------invoke--------------------------
void CallFBO(int CubeID)
{
glMatrixMode(GL_MODELVIEW);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_fbo);
--------------------------skip first and se cond texture object,they save the other result s --------------------------
int ID = CubeID+2;
glDrawBuffer(ATTACHMENT_ARRAY[ID]);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Set_Camera_Eye();

glUseProgram(programShader_Compositing);
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, g_texture2D[0]);


glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, g_texture2D[1]);
GLuint texLoc;
texLoc = glGetUniformLocationARB(programShader_Compositing, "FirstMap");
glUniform1iARB(texLoc, 0);
texLoc = glGetUniformLocationARB(programShader_Compositing, "SecondMap");
glUniform1iARB(texLoc, 1);

drawBack(CubeID);
}

----------------------------------------------
the strange problem is that, I do
CallFBO(0); and CallFBO(1); is OK! it ca n render to correct texture object! But I do CallFBO(2);It is error , nothing can be render!

then I write a simple test shader :
uniform sampler2D FirstMap;--------------------------first texture object--------------------------
uniform sampler2D SecondMap;--------------------------second texture bject--------------------------
void main()
{
float xx,yy,c = 512.0;
xx = gl_FragCoord.x / c;
yy = gl_FragCoord.y / c;
gl_FragColor.rgb = texture2D(SecondMap,vec2(xx, yy));
}

If I invoke callFBO(0) or callFBO(1), it will show a color cube,it is OK ,but now it nothing can see if I invoke callFBO(2) ;


I don't know where have a error!Who can gi ve me some help?

thanks advanced!

spring
01-02-2007, 07:29 PM
//why not initilize code can not post ,say have some html tag? for loop?

i = 0->4
glGenTextures(1, &g_texture2D[i]);
glBindTexture(GL_TEXTURE_2D, g_texture2D[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_BGRA, GL_FLOAT, 0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,ATTAC HMENT_ARRAY[i],GL_TEXTURE_2D, g_texture2D[i], 0);

sqrt[-1]
01-03-2007, 12:08 AM
Put your code in a

[CODE] [ /CODE] block. (without the space in the /CODE)

ZbuffeR
01-03-2007, 03:18 AM
And FYI, the double pipe breaks something here, even within code blocks, ie. beware of C boolean OR tests ...

spring
01-03-2007, 03:49 AM
Oh,I see! Thanks
But I more desire the reply which could get me out trouble!

sqrt[-1]
01-03-2007, 04:22 PM
I am not sure I am reading your code correctly, but what I see is this:

You initialize 0,1,2,3 attachments in a FBO:

i = 0->4
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,ATTAC HMENT_ARRAY[i],GL_TEXTURE_2D, g_texture2D[i], 0);


Your try to access 2,3,4 attachments (with the +2)

int ID = CubeID+2;
glDrawBuffer(ATTACHMENT_ARRAY[ID]);

So 4 is not init, when you call CallFBO(2)

spring
01-03-2007, 04:42 PM
Oh,No, I am sure that GL_COLOR_ATTACHMENT4_EXT had been initialized! I use for(int i = 0;i < 5;++i) ....

sqrt[-1]
01-04-2007, 01:37 AM
I think you are going to have to post a link to your source code or an .exe if you want more help (at least from me)