Please help, transparent sprites

Started by
3 comments, last by dpadam450 16 years, 1 month ago
I am trying to do masking and it just is not working. Here is my drawing code

glEnable(GL_BLEND);
		glBindTexture(GL_TEXTURE_2D, player.maskID);
		glBlendFunc(GL_DST_COLOR,GL_ZERO);
		glBegin(GL_QUADS);									// Start Drawing A Textured Quad
			glTexCoord2f(0.0f, 0.0f); glVertex2f(player.bottom.x, player.bottom.y);	// Bottom Left
			glTexCoord2f(1.0f, 0.0f); glVertex2f(player.top.x, player.bottom.y);	// Bottom Right
			glTexCoord2f(1.0f,  1.0f); glVertex2f(player.top.x, player.top.y);	// Top Right
			glTexCoord2f(0.0f,  1.0f); glVertex2f(player.bottom.x, player.top.y);	// Top Left
		glEnd();	

		glBindTexture(GL_TEXTURE_2D, player.textureID);
		glBlendFunc(GL_ONE,GL_ONE);
		glBegin(GL_QUADS);									// Start Drawing A Textured Quad
			glTexCoord2f(0.0f, 0.0f); glVertex2f(player.bottom.x, player.bottom.y);	// Bottom Left
			glTexCoord2f(1.0f, 0.0f); glVertex2f(player.top.x, player.bottom.y);	// Bottom Right
			glTexCoord2f(1.0f,  1.0f); glVertex2f(player.top.x, player.top.y);	// Top Right
			glTexCoord2f(0.0f,  1.0f); glVertex2f(player.bottom.x, player.top.y);	// Top Left
		glEnd();
	glDisable(GL_BLEND);

Any help would be appreciated. Or a good way to load PNGs so far I've tried corona and DevIL and both crash (using MSVC 2008 Express) [Edited by - halogen64 on March 6, 2008 7:11:07 AM]
Advertisement
Are you just trying to show only a portion of the texture you are loading? If so why not use like you said a .png or .tga file with alpha channel, and use

glEnable(GL_ALPHA_TEST);
glAlphaFunc();//setup how you want it to work
//draw stuff
glDisable(GL_ALPHA_TEST);

Not sure why you are using blending unless you want the sprite to have some level of transparency then yes use it. If you just want a explosion texture or water foam look use alpha testing.


Hey Mars_999, I am trying to load a (bmp, png, tga, don't care) image that has a spaceship that moves around the screen. I am currently trying to do it with a mask, I don't understand the glAlpha function very well so maybe you could explain it in more detail. For the moment though, I'd like to learn how to make the masking work or to be able to load a png with alpha.
If you want to mask then look at

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20

myself I would just make a texture with an alpha channel and in a word mask it off with the alpha testing with OpenGL.
What is the result. Make sure you disable depth testing before drawing the mask.


glBlendFunc(SRC_MULITLY, DST_MULITPLY);

if source mask pixel is black (0.0), then 0.0*GL_DST_COLOR = 0;
if source mask pixel is white (1.0), then 1.0*GL_DST_COLOR = whatever color was already there.

So all the white parts are see through, all the black parts are places that you want to draw.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement