Search code examples
javaopengllwjglmaskmasking

LWJGL using texture as alpha mask


I am creating a 2D game with lwjgl and slick-util. For a special feature in my game I wanted to be able to give textures a certain opacity. I have managed to figure this out but the next step is giving a Texture as a paramter which will give me the ability to give certain textures certain opacities in certain spots.

Note: I have gotten it sort of working before, but the mask also seemed to remove my background image, which I do not want.

I cannot post images because I dont have enough reputation or something but anyway what I want to basically do is:

  • first render a background image.
  • then render another images on top with a mask on it, I do not want this mask to apply onto the background.

How would I go about doing this?


Solution

  • I think you use wrong blending mode. If you did not change default blending mode, then you need:

    glEnable (GL_BLEND); // Enable blending.
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Setup blending function.
    

    I think in you case, texture does not blend with background, it simple replaces background.