Skip to main content
GameDev.net gamedev.net
🔒 Locked

textures and transparency

Started by black_blizzard Jun 26, 2007 at 1:16 PM 2 replies 1.3k views
Original Post
black_blizzard
black_blizzard
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.
Brother Bob
Brother Bob
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?
black_blizzard
black_blizzard
As I said, as a prey is getting eaten, I progressively turn it transparent -- this is done by decrementing the alpha value until it's 0.
black_blizzard
black_blizzard
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).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.