Original Post
hello evrey one ..
i find a code about transparent texture the code draw just one transparent texture on object i tried to draw a line behind it but the line i can not see it this is the code PS:"sorry for my bad english
"
void loadTexture( void )
{
AUX_RGBImageRec *pImage_RGB = auxDIBImageLoad( ".\\door.bmp" );
unsigned char *pImage_RGBA = NULL;
if( pImage_RGB != NULL )
{
int imageSize_RGB = pImage_RGB->sizeX * pImage_RGB->sizeY * 3;
int imageSize_RGBA = pImage_RGB->sizeX * pImage_RGB->sizeY * 4;
// allocate buffer for a RGBA image
pImage_RGBA = new unsigned char[imageSize_RGBA];
//
// Loop through the original RGB image buffer and copy it over to the
// new RGBA image buffer setting each pixel that matches the key color
// transparent.
//
int i, j;
for( i = 0, j = 0; i < imageSize_RGB; i += 3, j += 4 )
{
// Does the current pixel match the selected color key?
if( pImage_RGB->data == g_keyColor[0] &&
pImage_RGB->data[i+1] == g_keyColor[1] &&
pImage_RGB->data[i+2] == g_keyColor[2] )
{
pImage_RGBA[j+3] = 0; // If so, set alpha to fully transparent.
}
else
{
pImage_RGBA[j+3] = 255; // If not, set alpha to fully opaque.
}
pImage_RGBA[j] = pImage_RGB->data;
pImage_RGBA[j+1] = pImage_RGB->data[i+1];
pImage_RGBA[j+2] = pImage_RGB->data[i+2];
}
glGenTextures( 1, &g_textureID );
glBindTexture(GL_TEXTURE_2D, g_textureID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Don't forget to use GL_RGBA for our new image data... we support Alpha transparency now!
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, pImage_RGB->sizeX, pImage_RGB->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pImage_RGBA );
}
if( pImage_RGB )
{
if( pImage_RGB->data )
free( pImage_RGB->data );
free( pImage_RGB );
}
if( pImage_RGBA )
delete [] pImage_RGBA;
}
//-----------------------------------------------------------------------------
// Name: init()
// Desc:
//-----------------------------------------------------------------------------
void init( void )
{
GLuint PixelFormat;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;
g_hDC = GetDC( g_hWnd );
PixelFormat = ChoosePixelFormat( g_hDC, &pfd );
SetPixelFormat( g_hDC, PixelFormat, &pfd);
g_hRC = wglCreateContext( g_hDC );
wglMakeCurrent( g_hDC, g_hRC );
loadTexture();
glClearColor( 0.35f, 0.53f, 0.7f, 1.0f );
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 45.0f, 640.0f / 480.0f, 1.0f, 100.0f);
}
//...
//...
void render( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_TEXTURE_2D);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
// glTranslatef( 0.0f, 0.0f, -6.0f );
glTranslatef( 0.0f, 0.0f, -6.0f );
glPushMatrix();
glRotatef( -g_fSpinY, 1.0f, 0.0f, 0.0f );
glRotatef( -g_fSpinX, 0.0f, 1.0f, 0.0f );
if( g_bBlendOutColorKey == true )
{
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}
//glDisable(GL_DEPTH_TEST);
glBindTexture( GL_TEXTURE_2D, g_textureID );
/* glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices );
glDrawArrays( GL_QUADS, 0, 4 );*/
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);glVertex3f(-1.0f,-1.0f, -0.0f);
glTexCoord2f(1.0f,0.0f);glVertex3f(1.0f,-1.0f, -0.0f );
glTexCoord2f(1.0f,1.0f);glVertex3f(1.0f, 1.0f, -0.0f );
glTexCoord2f(0.0f,1.0f);glVertex3f(-1.0f, 1.0f, -0.0f);
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
//glColor3f(0,0,0);
glTranslatef( 0.0f, 0.0f, -8.0f );
glBegin(GL_LINE_LOOP);
glVertex3f(1,.5,0);
glVertex3f(.5,1,0);
glEnd();
SwapBuffers( g_hDC );
}