|
|

楼主 |
发表于 2005-10-12 14:38:00
|
显示全部楼层
Re: 求助:关于多纹理映射
- void CMainFrame::LoadTexture()
- //-----------------------------------------------------------------------------
- // Name: loadTexture()
- // Desc:
- //-----------------------------------------------------------------------------
- {
- AUX_RGBImageRec *pImage_RGB = auxDIBImageLoad( "texture0.bmp" );
- AUX_RGBImageRec *pImage_alpha = auxDIBImageLoad( "texture1.bmp" );
- unsigned char *pImage_RGBA = NULL;
- if( pImage_RGB != NULL && pImage_alpha != 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 )
- {
-
- pImage_RGBA[j+3] = pImage_alpha->data[i+0]; // If so, set alpha to fully transparent.
-
- pImage_RGBA[j] = pImage_RGB->data[i];
- pImage_RGBA[j+1] = pImage_RGB->data[i+1];
- pImage_RGBA[j+2] = pImage_RGB->data[i+2];
- }
- glGenTextures( 1, &g_textureID_0 );
- glBindTexture( GL_TEXTURE_2D, g_textureID_0 );
- 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;
- }
复制代码 |
|