Jump to content
  • Advertisement
Sign in to follow this  
black_blizzard

textures and transparency

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

Hi everyone. I'm having problems with transparency using textures and I'd appreciate some help. The thing is I'm making this assignment for class in which there are fishes swimming around and when a prey gets eaten by a predator I simulate the "eating" by making the prey progressively turn transparent. This worked just fine when I wasn't using textures, but I can't seem to make it work when there are textures applied, and I can't figure out why. I think this is all the transparency- or texture-related code I have: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ..... glEnable(GL_TEXTURE_2D); Vertex4f white(1, 1, 1, 1); //Vertex4f has format RGBA. glMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat *) &white); glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat *) &white); glMaterialfv(GL_FRONT, GL_SPECULAR, (GLfloat *) &white); glMaterialf(GL_FRONT, GL_SHININESS, shininess); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D(GL_TEXTURE_2D, 0, 4, texture.width(), texture.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, &(texture.pixels()[0])); ..... //here I draw my triangles glDisable(GL_TEXTURE_2D); I think that's it. Another thing: I'm using my textures with the alpha value 255 (ie, 1). And this is the code that executes when I'm not using textures, which *does* work transparency-wise: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ..... glMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat *) &colors[AMBIENT_COLOR]); glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat *) &colors[DIFFUSE_COLOR]); glMaterialfv(GL_FRONT, GL_SPECULAR, (GLfloat *) &colors[SPECULAR_COLOR]); glMaterialf(GL_FRONT, GL_SHININESS, shininess); ..... //here I draw my triangles Any input? Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
If your texture's alpha channel is 1, and the alpha channel in the lighting color settings are 1, where do you expect the transparency information to come from?

Share this post


Link to post
Share on other sites
Ok, I figured it out. It was just a stupid slip (I changed some things that affected certain parts of my code, but I did it fast and hadn't realized it yet).

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!