I want to create an image which I can use as a texture in OpenGL. The image is a jpg that comes in red.

In my OpenGL I want to be able to change the red color to any other color the user selects, for this i thought the best solution was just to discard the rgb channels from the original image and only use the alpha channel of the texture, and the rgb the user selected.

The problem is that even thought I have tried for quite some time, this only seems to work for the edges of the image, not the inner part of the image.

This is the example image:

enter image description here

As it can be seen, there are parts that are in pure red, others that are mixed with white, and complete white parts. I need to have "a png alpha image" in where white represents transparent. This means that complete red will have an alpha of 1.0, complete white an alpha of 0.0 and anything in between an alpha between 0.0-1.0.

In OpenGL I have access to the r,g,b,a channels of the texture. So if anyone has another solution that doesn't use alpha that would help too.


1 Answer 1


I guess you need something like this:

enter image description here

enter image description here

Where deepest red is 100% black. It is not hard to do. You can experiment a bit more with it by:

  1. Desaturate your image to grayscale

  2. Open Levels and tune it up as you need.

I also have done it as PNG with transparency https://dl.dropboxusercontent.com/u/1007168/Untitled-1.png Please check if this is what you need.

To do it as PNG with transparency and ready for recolor:

  1. Select your layer with image and copy to clipboard. Then create a new mask: enter image description here

  2. Paste your image from clipboard to the mask: enter image description here

  3. Turn off the mask and back to usual RGB channels: enter image description here

  4. Hold Ctrl (Cmd) key and click over little thumb of your mask at Channels palette: enter image description here

  5. Now you can delete the white. Press DEL: enter image description here

To check how it works you can try to recolor it by yourself:

  1. Switch on "Hold transparent pixel": enter image description here

  2. Fill it up with any color: enter image description here

Here is the sample how it looks recolored in different colors: enter image description here

  • Hello, thanks for the response. Yes this is exactly what I am looking for. I did what you told me there and converted to grayscale, then moved the levels. But im not sure what to do after... The thing is that I need to do this for around 16 different patterns (that will be used in a texture map) so i have to figure out the procedure.
    – Pochi
    Commented Jun 4, 2014 at 9:01
  • @Chiquis, do you need your masks as PNGs with transparency (instead white)?
    – Vnovak
    Commented Jun 4, 2014 at 9:04
  • Yeah, what I need is to be able to create that image that you made. It is exactly what i need. I adjusted the "levels" to make it a bit more darker but I don't know how to go from that step to a png with transparency.
    – Pochi
    Commented Jun 4, 2014 at 9:08
  • Ok, adding info to answer how to do a PNG with transparency (ready for recolor) next
    – Vnovak
    Commented Jun 4, 2014 at 9:10
  • Too bad Photoshop lacks Gimp's "Color to alpha" command.
    – mireazma
    Commented Nov 1, 2020 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.