Jump to content
  • Advertisement
Sign in to follow this  
L. Spiro

Drawing a Sprite with Transparency

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

From my previous topic one can tell that I have really tried many things to get this to work and still it fails, so let me start over from scratch. I have this: http://img522.imageshack.us/img522/512/defaultsx7.gif I want it to look like this: http://img149.imageshack.us/img149/4734/desiredbb0.gif I am drawing a quad using this:
glBindTexture( GL_TEXTURE_2D, * );

glVertexPointer( 3, GL_FLOAT, 0, * );

glTexCoordPointer( 2, GL_FLOAT, 0, * );

glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
How can I obtain the desired result, aside from simply making a new image that is half transparent? Regards, L. Spiro

Share this post


Link to post
Share on other sites
Advertisement
You need to set up blending [using glBlendFunc() and glEnable(GL_BLEND)], and use glColor4f() to set an alpha (transparency) value, before you draw. Tutorials abound on the internet, and the man pages for those functions are also very handy.

Share this post


Link to post
Share on other sites
Blending is enabled and I used glColor4f() as well as glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND ) and glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, * ).


You may read up on the previous dicsussion here: http://www.gamedev.net/community/forums/topic.asp?topic_id=515162


glColor4f() is always ignored. It does nothing, regardless of what blending modes/functions I have set.


I really need the solution urgently; it has been over a week since I posted the original question but the deadline on my project has not been pushed back.


Thank you,
L. Spiro

Share this post


Link to post
Share on other sites
Quote:
Original post by YogurtEmperor
glColor4f() is always ignored. It does nothing, regardless of what blending modes/functions I have set.
Looking at your example image, it appears that the image has an alpha channel, so you want to blend based on the texture's alpha channel multiplied by a constant factor of 0.5. Please correct my assumptions if they are incorrect.

Given that that is the case, you need to call glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE), so that the incoming colour is multiplied by the texture colour. Then you need to glEnable(GL_BLEND), and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), for standard blending. Lastly you need to call glColor4f(1.0, 1.0, 1.0, 0.5), to set your constant factor of 0.5 alpha (with full colour intensity).

If this doesn't work, post back, but make sure that your [BaseSprite drawAtPoint:] method isn't changing the colour (i.e. make sure that your vertices are not being specified with a colour component).

Share this post


Link to post
Share on other sites
Thank you; that is just what I needed.

It seems I was doing all the right things, but not together at the same time.


L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!