Jump to content


OpenGL glTexImage2D and Transparency


3 replies to this topic

#1 jedij

    New Member

  • Members
  • Pip
  • 8 posts

Posted 30 January 2008 - 02:51 PM

Im using glTexImage2D to create a texture. Where im having a problem is that my clear color is green and the texture keeps that color for the background in the created image. I was wondering if theres any way to make the background color transparent so that the only thing that shows is the black and blue lines that I want to show?

#2 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 30 January 2008 - 03:29 PM

Loop through all of the pixels and set the alpha value for the green ones.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#3 jedij

    New Member

  • Members
  • Pip
  • 8 posts

Posted 30 January 2008 - 03:31 PM

monjardin said:

Loop through all of the pixels and set the alpha value for the green ones.

can you give me an example of how to do this?

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 30 January 2008 - 04:38 PM

Do you understand how texture images are laid out in memory? Assuming you're using GL_RGBA format, each pixel is just four bytes, one each for red, green, blue, and alpha. You just need to get a pointer to the image data and make a loop that goes through each pixel, examines the color components and determines if it's green, and if so sets the alpha of that pixel to zero (the alpha of the opaque pixels should be 255).
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users