Sign in to follow this  
L. Spiro

Drawing a Sprite with Transparency

Recommended Posts

L. Spiro    25638
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
L. Spiro    25638
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
swiftcoder    18437
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this