をロードしてOpenGLテクスチャに変換するために使用しているコードがありますがSDL_Surface
、RGB(A)サーフェスでのみ機能することに気付きました。インデックスモードの画像(透明度の有無にかかわらず)にサポートを拡張する必要があります。
最初は調べていましたが::SDL_SetColorKey()
、SDLブリットでしか機能しないようです。、、を読みSDL_Surface
、次のスケッチを始めました(//#は擬似コードです)。SDL_PixelFormat
SDL_Color
SDL_Surface *pSurf(::IMG_Load(image));
::SDL_LockSurface(pSurf);
Uint32 bytesPerPixel(pSurf->format->bytesPerPixel);
GLenum pixelFormat;
Uint8 *pixelData(pSurf->pixels);
bool allocated(false); // pixelData isn't allocated
if(pSurf->format->palette != 0) // indexed mode image
{
//# Determine transparency. // HOW?
//# bytesPerPixel = 3 or 4 depending on transparency being present;
//# pixelFormat = GL_RGB or GL_RGBA depending on bytesPerPixel;
Uint32 blockSize(pSurf->w * pSurf->h * bytesPerPixel);
pixelData = new Uint8[blockSize];
allocated = true;
//# traverse pSurf->pixels, look up pSurf->format->palette references and copy
// colors into pixelData;
}
else
{
//# Determine pixelFormat based on bytesPerPixel and pSurf->format->Rmask
// (GL_RGB(A) or GL_BGR(A)).
}
//# Pass bytesPerPixel, pixelFormat and pixelData to OpenGL (generate texture,
// set texture parameters, glTexImage2D etc).
if(allocated)
{
delete[] pixelData;
pixelData = 0;
}
::SDL_UnlockSurface(pSurf);
::SDL_FreeSurface(pSurf);
したがって、問題は、このルーチンに渡すインデックス付きモードの画像に透明性があるかどうかをどのように判断できるかということです。