Game Development Reference
In-Depth Information
3.
We load a texture from a bitmap through the following code:
void clGLTexture::LoadFromBitmap( const clPtr<clBitmap>& B )
{
if ( !FTexID ) LGL3->glGenTextures( 1, &FTexID );
ChooseInternalFormat( B->FBitmapParams, &FFormat,
&FInternalFormat );
Bind( 0 );
LGL3->glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_LINEAR );
LGL3->glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_LINEAR );
4.
Not all texture wrapping modes are supported in OpenGL ES 2. Particularly, GL_
CLAMP_TO_BORDER is unsupported:
#if defined( ANDROID )
LGL3->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE );
LGL3->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE );
#else
LGL3->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_BORDER );
LGL3->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_BORDER );
#endif
LGL3->glTexImage2D( GL_TEXTURE_2D, 0, FInternalFormat,
B->GetWidth(), B->GetHeight(), 0, FFormat,
GL_UNSIGNED_BYTE, B->FBitmapData );
}
5.
There is a helper function ChooseInternalFormat() , that we use to select
the appropriate OpenGL image formats for our bitmap, either RGB or RGBA. The
implementation looks like the following code:
bool ChooseInternalFormat( const sBitmapParams& BMPRec,
GLenum* Format, GLenum* InternalFormat )
{
if ( BMPRec.FBitmapFormat == L_BITMAP_BGR8 )
{
#if defined( ANDROID )
*InternalFormat = GL_RGB;
*Format = GL_RGB;
#else
*InternalFormat = GL_RGB8;
*Format = GL_BGR;
#endif
}
 
Search WWH ::




Custom Search