Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Combining textures with fixed alpha

  1. #1
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    2

    Combining textures with fixed alpha

    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.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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.

  3. #3
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    2
    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?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •