PDA

View Full Version : Combining textures with fixed alpha



kanowins
12-10-2012, 11:57 PM
Hello,

I'm very beginner with opengl, I'm developing a 2d game using Opengl 1.1. I found solution for almost all my needs but I can't find how to do the next:

I want to use 3 textures for a rectangle

- 2 opaque textures
- 1 texture with alpha channel

I want to merge the 2 opaque textures applying an arbitrary alpha to the second one. The alpha is not constant, it will be changed with every draw.

Then, combine the result using multiply with the texture with alpha channel.

Is this possible? Can you post an example code?

Thanks in advance.

tonyo_au
12-11-2012, 12:55 AM
have a look at stencils - render your first texture, render the alpha channel texture as a stencil then with stencils enabled render the second texture. - checkout stenciling on the net there will be examples available.

kanowins
12-11-2012, 02:15 AM
Thank you for your reply :), but I think you don't get my question or I don't get the reply.

I want to draw one opaque texture over the other opaque texture applying a random alpha. I can't imagine how to do this with your reply.

Let's put things clearer:

1-. texture1 opaque
2-. texture2 opaque
merge them applying a random alpha

3-. texture3 with alpha channel
combine (multiply) with the result texture in the last step (at least I know how to do this step).

When you said "render the alpha channel texture", did you mean the texture2 texture?

tonyo_au
12-11-2012, 09:58 PM
sorry i thought you meant to use the alpha as a simple selection between the 2 textures - you want to blend.

In Opengl 1.1, I think the easiest is to create an RGBA texture and combine the RGB from the second texture with the alpha channel texture each frame then render with alpha blending

Can I ask what device is restricted to OpenGL 1.1?