0

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?

Vulcano
  • 155
  • 9

1 Answers1

0

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.

Unick
  • 644
  • 9
  • 23
  • I see, do you have any suggestion on how to stop it replacing my background? Should I render the background after I rendered the masked texture? – Vulcano Jul 15 '15 at 11:20
  • You need to use blending. If blending is disabled, transparent pixels from texture replace background pixels. If you use blending, transparent pixels will not replace background pixels. – Unick Jul 15 '15 at 12:09