PDA

View Full Version : image alpha



04-09-2003, 01:13 PM
I'm just writing a sample openGL program to learn the basic's, and my question is: what gl functions and (in what order to call 'em) do I need to make the colors of my texture transparent for the following world object? Do I need to turn depth test/buffer off? Oh, and my image is an alpha image (ie. 4 bytes, 1 for each of R, G, B and 1 for the alpha) and I have set all the alpha'a (0 or 255). TIA!


...
post = glGenLists(1);

glNewList(post, GL_COMPILE);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);

for (int i = 0; i < 2; ++i) // For example.
{
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f + i, 0.0f, 1.0f + i);
glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f + i, 0.0f, 1.0f + i);
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f + i, 1.0f, 1.0f + i);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f + i, 1.0f, 1.0f + i);

glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f + i, 0.0f, 0.5f + i);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f + i, 0.0f, 1.5f + i);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f + i, 1.0f, 1.5f + i);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f + i, 1.0f, 0.5f + i);
}
glEnd();

glDisable(GL_TEXTURE_2D);

glEndList();
...

nexusone
04-09-2003, 01:35 PM
You create an transparentcy map with Alpha channel, nehe.gamedev.net has a good tutor on it. tutor I think 33 or 32...



Originally posted by unmae:
I'm just writing a sample openGL program to learn the basic's, and my question is: what gl functions and (in what order to call 'em) do I need to make the colors of my texture transparent for the following world object? Do I need to turn depth test/buffer off? Oh, and my image is an alpha image (ie. 4 bytes, 1 for each of R, G, B and 1 for the alpha) and I have set all the alpha'a (0 or 255). TIA!


...
post = glGenLists(1);

glNewList(post, GL_COMPILE);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);

for (int i = 0; i < 2; ++i) // For example.
{
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f + i, 0.0f, 1.0f + i);
glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f + i, 0.0f, 1.0f + i);
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f + i, 1.0f, 1.0f + i);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f + i, 1.0f, 1.0f + i);

glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f + i, 0.0f, 0.5f + i);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f + i, 0.0f, 1.5f + i);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f + i, 1.0f, 1.5f + i);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f + i, 1.0f, 0.5f + i);
}
glEnd();

glDisable(GL_TEXTURE_2D);

glEndList();
...

04-10-2003, 01:17 PM
I know that!, but what is the complete list of functions that I must call to make my transparent areas on my image TRANSPARENT when rendered??? TIA.

nexusone
04-10-2003, 03:36 PM
Here is a bit of code to call when using the alpha as a mask.
Note on your alpha mask, 1= non-transparent, 0=transparent.


glEnable(GL_BLEND); // blending must be enabled
glDisable(GL_DEPTH_TEST); // may or may not need depending on the application
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Set's up how alpha should effect image. We are using blending based on the alpha channel.
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, store_textures[texture] );

glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glTexCoord2f(0.0f,0.0f ); glVertex3f(-1.0f,-2.0f,0.0f);
glTexCoord2f(1.0f,0.0f ); glVertex3f( 1.0f,-2.0f,0.0f);
glTexCoord2f(1.0f,1.0f ); glVertex3f( 1.0f, 2.0f,0.0f);
glTexCoord2f(0.0f,1.0f ); glVertex3f(-1.0f, 2.0f,0.0f);
glEnd();
glDisable( GL_TEXTURE_2D );


Originally posted by i:
I know that!, but what is the complete list of functions that I must call to make my transparent areas on my image TRANSPARENT when rendered??? TIA.