Archived

This topic is now archived and is closed to further replies.

MetroidHunter

Blending in OpenGL help

Recommended Posts

Using openGL, I''m try remove the black background on a bitmap. However, whenever I try to do this, the image becomes partially transparent. How can I correct this?
  
BOOL Initialize (GL_Window* window, Keys* keys)					// Any GL Init Code & User Initialiazation Goes Here

{
	g_window	= window;
	g_keys		= keys;

	// Start Of User Initialization

	angle		= 0.0f;											// Set Starting Angle To Zero


    if (!LoadGLTextures())						 	            // Jump To Texture Loading Routine

	{
		return FALSE;							                // If Texture Didn''t Load Return FALSE

	}
	glEnable(GL_TEXTURE_2D);						            // Enable Texture Mapping

	glClearColor (0.0f, 0.0f, 0.0f, 0.5f);						// Black Background

	glClearDepth (1.0f);										// Depth Buffer Setup

	glDepthFunc (GL_LEQUAL);									// The Type Of Depth Testing (Less Or Equal)

	glEnable (GL_DEPTH_TEST);									// Enable Depth Testing

	glShadeModel (GL_SMOOTH);									// Select Smooth Shading

	glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);			// Set Perspective Calculations To Most Accurate

	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);				// Setup The Ambient Light

	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);				// Setup The Diffuse Light

	glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);			// Position The Light

	glEnable(GL_LIGHT1);			             				// Enable Light One

	glEnable(GL_LIGHTING);		                                // Enable Lighting

	glBlendFunc(GL_SRC_ALPHA,GL_ONE);			// Set The Blending Function For Translucency

glEnable(GL_BLEND);					// Enable Blending


	return TRUE;												// Return TRUE (Initialization Successful)

}
.
.
.
(in draw function)
glBegin (GL_QUADS);		//  draws the character

 
      glTexCoord2f(0.0f,  0.0f);	glVertex3f(  xpos, ypos, zpos);
	  glTexCoord2f(1.0f,  0.0f);	glVertex3f(xpos+1, ypos, zpos);
	  glTexCoord2f(1.0f,  1.0f);	glVertex3f(xpos+1, ypos+1, zpos);
	  glTexCoord2f(0.0f,  1.0f);	glVertex3f(  xpos, ypos+1, zpos);
	glEnd();  

Share this post


Link to post
Share on other sites
hmmm....

you might want to use "additive"-blending: glBlendFunc(GL_ONE, GL_ONE)

otherwise, you could write a convertation func that *inserts* alpha to your texture and set''s alpha on all those texels to 0 (invisible) where the addition of green, red & blue bytes is 0 (this is, black) - else to 0xff

Share this post


Link to post
Share on other sites