1 Replies - 9011 Views - Last Post: 20 August 2008 - 10:22 PM Rate Topic: -----

#1 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 995
  • Joined: 30-July 08

openGL transparent color

Posted 20 August 2008 - 06:14 PM

I try to get the color #ff00ff transparent without much luck.
glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1, 1, 1, 0.8f);
		aSprite = 0;
		glBindTexture(GL_TEXTURE_2D, sprite[aSprite]);
		glBegin(GL_POLYGON);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(float(sxPos + sprx), float(syPos + spry), 0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(float(sxPos + 1 + sprx), float(syPos + spry), 0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(float(sxPos + 1 + sprx), float(syPos + 1 + spry), 0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(float(sxPos + sprx), float(syPos + 1 + spry), 0.0f);
		glEnd();
		glDisable(GL_BLEND);

This makes the entire sprite transparent and thats really not what I want to do.

This is how it looks right now
Attached Image

This is how I want it to look
Attached Image

Best regards!

Is This A Good Question/Topic? 0
  • +

Replies To: openGL transparent color

#2 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Re: openGL transparent color

Posted 20 August 2008 - 10:22 PM

Unrelated to your problem but you should probably be using GL_QUAD instead of GL_POLYGON (since it seems you're just drawing a quad). :)

I'm a little tired right now, but basically what it looks like you're doing is drawing a rectangle and putting a texture on it. Your texture is an RGB image with a purple background that you want to represent transparency.

Pretty sure that call to glColor* is setting the color to white with an alpha/opacity value of 0.8 [which is probably not what you intend].

Basically what you need to do is to put your image into a format that stores alpha [ie. opacity] values, f.ex. TGA. OpenGL doesn't know that #ff00ff means transparent, because #ff00ff is just another RGB color. Transparency in OpenGL is handled by playing with the alpha value [ie. RGBA = Red Green Blue Alpha].

You could try to do some kind of color masking to convert your RGB texture to a RGBA texture during runtime, but I think that would be a lot more work.

I wrote a TGA loader snippet I believe that supported loading uncompressed 24bit TGAs if you want to take a look. :^:

Hope all of that makes sense, I need sleep. :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1