Skip to main content
gamedev.net
🔒 Locked

Transparency- Help Please

Started by jimgeagea 0 replies 400+ views
Original Post
jimgeagea
jimgeagea
Hi, i have 2 2D textures on a quad, a big texture set as a background, and a small texture to put on top of the first texture, so the small texture has a color value green, which i dont want it to be shown. How can i do this? //this is my render function, where i am rendering the 2 textures Render() { glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D);//(NEW) Enable 2D texturing //big texture glBindTexture(GL_TEXTURE_2D, textures[0]); glPushMatrix(); glBegin(GL_QUADS); glTexCoord2f(0,1);//This is the upper left corner of the square glVertex2f(-3.5f,2.1); glTexCoord2f(1,1);//This is the upper right corner of the bitmap glVertex2f(3.5f,2.1); glTexCoord2f(1,0);//This is the lower right corner of the bitmap glVertex2f(3.5f,-3.5); glTexCoord2f(0,0);//The lower left corner glVertex2f(-3.5f,-3.5); glEnd(); glPopMatrix(); //smaller texture glBindTexture(GL_TEXTURE_2D, textures[1]); glPushMatrix(); glBegin(GL_QUADS); glTexCoord2f(0,1);//This is the upper left corner of the square glVertex2f(-1.5f,1.1); glTexCoord2f(1,1);//This is the upper right corner of the bitmap glVertex2f(1.5f,1.1); glTexCoord2f(1,0);//This is the lower right corner of the bitmap glVertex2f(1.5f,-0.5); glTexCoord2f(0,0);//The lower left corner glVertex2f(-1.5f,-0.5); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); glutSwapBuffers(); }
Schrompf
Schrompf
There's maybe a ColorKey function that does this for you. Have a look at the OpenGL docs. The "real" way to do would be to use the alpha channel. You lock into your texture, set the alpha value for each pixel to 0.0f if the color is green or 1.0f for all other pixels, then unlock the texture again. You can now use AlphaTesting to kill all pixels below a certain alpha value or AlphaBlending to mix the texture color with the background color according to the texture alpha value.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

Topic Locked

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

Sign in to reply to this topic.