Jump to content
  • Advertisement
Sign in to follow this  
CodeBox

transparent textures?

This topic is 4860 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

I have got textures on my program but I can't figure out how to make the white bits of the textures transparent? Here is some of my code just encase you need it!
GLuint LoadTexture(char *filename) { 
	GLuint texID; 
	AUX_RGBImageRec *image = auxDIBImageLoad(filename); 
	glGenTextures(1, &texID); 
	glBindTexture(GL_TEXTURE_2D, texID); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image->data); 
	return texID; 
} 

static void instructionsBackground(){
	glEnable(GL_TEXTURE_2D); 
	glBindTexture(GL_TEXTURE_2D, waterId); 
	glBegin(GL_QUADS); 
	glColor3f(1,1,1); 
	glTexCoord2f(10.0f, 10.0f); glVertex2d(winL,winT);
	glTexCoord2f(10.0f, 0.0f); glVertex2d(winL,winB);
	glTexCoord2f(0.0f, 0.0f); glVertex2d(winR,winB);
	glTexCoord2f(0.0f, 10.0f); glVertex2d(winR,winT);
	glEnd(); 
}



Share this post


Link to post
Share on other sites
Advertisement
I'm not sure if/how one sets a color to equal transparency. What you can do is add an alpha layer to your textures and then load them as RGBA. Then sort them back to front and render them with alpha blending enabled.

Share this post


Link to post
Share on other sites
Here is the code... Make sure your texture is setup to rgba


glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//draw stuff

glDisable(GL_ALPHA);
glDisable(GL_BLEND);



HTH

Share this post


Link to post
Share on other sites
Quote:
Original post by CodeBox
How Do I set the texture as RGBA?


Load a texture format like .tga or someother picture format that supports Alpha channel. Then load it into OpenGL with GL_RGBA types. Have the RGB portion of the texture greyscale and the alpha is a black/white representation of that which will determine what is transparent and what is not. Now after looking at your code, I see you are using the Aux loader. I don't think that works with anything other than .bmp? I am not sure, but if doesn't support .tga goto Nehe and look at the tutorial on loading .tgas or use a library like DevIL...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Now after looking at your code, I see you are using the Aux loader. I don't think that works with anything other than .bmp?


correct.

Quote:

I am not sure, but if doesn't support .tga goto Nehe and look at the tutorial on loading .tgas or use a library like DevIL...


Or the newly release GTL [grin]

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!