fbo alpha

Apprentice
Posts: 6
Joined: 2009.03
Post: #1
hello idevgames-people,

i am a opengl es newbie an have problems with rendering to a texture.
i generated a gaussian blurred image, i.e. values near 1.0f in the middle of the image, smoothly faded out to 0.0f in all directions to the borders of the image (imagine a black image getting white in the middle).

in my renderToTex function, i bind the framebuffer, bind the gaussian image and render some quads, then rebind the "standard" framebuffer.

the initialization code:
Code:
// Generate render target texture
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
    
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_texSize, m_texSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);


GLuint old = 0;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *) &old);
GLuint fbo = 0;
glGenFramebuffersOES(1, &fbo);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0);
    
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
        NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
        
}
glBindFramebufferOES(GL_FRAMEBUFFER_OES, old);



// Generate attenuation texture
GLuint attTexture;
glGenTextures(1, &attTexture);
glBindTexture(GL_TEXTURE_2D, attTexture);
    
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);


float data[128*128];
//in this function i create the gaussian image
CreateAttenuationImageData(size, data);

glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_FLOAT, data);


render to texture:
Code:
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_fboRender);
glClear(GL_COLOR_BUFFER_BIT);

glViewport(0, 0, m_texSize, m_texSize);
glDisable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, attTexture);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

//draw some quads...
for (some positions)
{   ...
   glVertexPointer(2, GL_FLOAT, 0, squareVertices);
   glTexCoordPointer(2, GL_FLOAT, 0, squareTexCoords);
   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

//bind "standard" framebuffer
glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFramebuffer);

after renderToTexture, i draw a blue background and then the rendertarget:

Code:
//enable alpha testing
glEnable(GL_ALPHA_TEST);
drawBlueBackground();
drawAlphaBackground();


the whole stuff should work, but i just get completely blue quads at their positions.
so i guess the renderToTex works, but their may be problems with the alphavalues or so...

this is a big post and i hope you can understand what i am trying to do...
please help me

greets
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.11
Post: #2
Hi kampfgnu,

Did you manage to make it work? I have a really hard time to accomplish similar results !
Quote this message in a reply
Post Reply