basic textures-blending question

Hi,

I’d like to draw two images (bitmaps) on top of each other and control the RGBA properties of each one independently.

How should I setup the blending to achieve that?

The full story:
I get the two images to appear just fine overlaying each other, but when I change the opacity (GL.GL_ALPHA_SCALE…) or any other gl.glPixelTransferf channel, both images are affected instead of just the one to which i’m trying to apply the change.

Here’s how i do it:
on the init of GLDrawable i do:
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

and in the display() method of each of the two objects (each object operates on a single texture) i do
gl.glPixelTransferf(GL.GL_ALPHA_SCALE, ); //same for rgb.

I also tried gl.glBlendFunc(GL.GL_ONE_MINUS_SRC_ALPHA, GL.GL_SRC_ALPHA);
this makes one of the images disappear when it is supposed to, but when i try to do the same change to the other image, it is still the first image that disappears!

So… as you can see i’m confused.

Any ideas?
Thank you,
Jill

You’ll get better performance if you turn the images into textures and draw them on quads.
If you do, you can use glColor4f(1, 1, 1, alpha) instead of playing with the pixel transfer state.

It still sounds strange that it only affects the first bitmap, though. Could you post the actual code?

Hi Markus,
Thank you for replying.
I incorporated your color4f suggestion - but the problem still persists.

here is the display() method (performed whenever a new picture has been loaded or a modification such as RGBA change has been requested):

============
//tex contains the texture info of the current image
//currByteBuffer contains the actual pixel data

gl.glPushMatrix();

gl.glBindTexture(GL.GL_TEXTURE_2D, tex.getTextureID());

gl.glBegin(GL.GL_QUADS); //this is same as in VSPUnit
gl.glTexCoord2f(tex2DQuad[0], tex2DQuad[1]);
gl.glVertex3f(tex3DQuad[0], tex3DQuad[1], 0.0f);
gl.glTexCoord2f(tex2DQuad[2], tex2DQuad[3]);
gl.glVertex3f(tex3DQuad[2], tex3DQuad[3], 0.0f);
gl.glTexCoord2f(tex2DQuad[4], tex2DQuad[5]);
gl.glVertex3f(tex3DQuad[4], tex3DQuad[5], 0.0f);
gl.glTexCoord2f(tex2DQuad[6], tex2DQuad[7]);
gl.glVertex3f(tex3DQuad[6], tex3DQuad[7], 0.0f);
gl.glEnd();

if (pixelTransferRequested) {
pixelTransferRequested = false;
gl.glColor4f(redV, greenV, blueV, opacityV);
}

gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, actualWidth, kHeight, 0, srcPixelFormat, GL.GL_UNSIGNED_BYTE, currByteBuffer);

gl.glPopMatrix();
gl.glFlush();

in a separate thread i load the images (once for stills, continuously for video).

my init() that is performed just once in the beginning is:

GL gl = drawable.getGL();
drawable.setGL(new DebugGL(drawable.getGL()));
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
gl.glClearDepth(1.0); //clear the entire buffer
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
gl.glColor4f(1.0f, 1.0f, 1.0f, 0.5F);
gl.glViewport(0, 0, width, height);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

finally, in the display() method of the higher-up object (the one that controls the two texture objects), i clear the screen each time before displaying the two textures:

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

Any ideas?
Thanks a lot!
Jill

You only set the color once. Try adding this on top of your display() method. (or rather, just before the glBegin for maximum readability and low bug chance):

gl.glColor4f(1, 1, 1, 1);