PDA

View Full Version : Problem with render to texture using pbuffer and alpha



PKH68
01-06-2009, 08:02 AM
I'm using pbuffer for rendering to texture. In the final texture I want a black/transparent background, as parts of it should be transparent.Rendering things into the texture works fine, and I can display it using 2 triangles. The problem is that the parts which hasn't been rendered to are supposed to be transparent, but they are displayed as black (which I cleared it to, but the alpha seems to be ignored).

I'm creating the config whith these params:


EGLint pi32ConfigAttribs[] = {
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
EGL_NONE
};

int iConfigs;
eglChooseConfig(y_gles_config.display,
pi32ConfigAttribs,
&y_gles_config.config,
1,
&iConfigs);


then I create the pBuffer with this:


EGLint attribs[] = { EGL_WIDTH, fTexWidth,
EGL_HEIGHT, fTexHeight,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_NONE};

fEglSurface = eglCreatePbufferSurface(y_gles_config.display,
y_gles_config.config,
attribs);


then I create the texture with this:


glGenTextures(1, &fTexId);
glBindTexture(GL_TEXTURE_2D, fTexId);

y_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
y_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
y_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
y_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fTexWidth, fTexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);


I use rgba for all texture formats.

I then set up the rendertarget with makeCurrent, set up viewport etc and clear it with:


y_glClearColor(yGLreal(0), yGLreal(0), yGLreal(0), yGLreal(0));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


I also enable blending, and set up the blendingfunction before rendering the 2 triangles with the final texture, so I think the problem is in the texture/surface. I searched on google and it seems that under regular GL, one must use GLUT_RGBA on glutInitialize to get alpha on framebuffers, but haven't found any similar options for GL ES 1.1. Any one got any tips ?

Xmas
01-06-2009, 09:12 AM
The glTexImage2D call is unnecessary since the pbuffer provides its own storage anyway when it's bound to the texture object. You might try requesting a config with at least one alpha bit, i.e. add (EGL_ALPHA_SIZE, 1) to pi32ConfigAttribs.

PKH68
01-07-2009, 01:44 AM
Thanks for responding. I've tried egl_alpha_size 1 and 8 and it still looks the same.