Game Development Reference
In-Depth Information
See also
F Manipulating geometry
Creating a wrapper for textures
In previous chapters, we already used OpenGL textures to render an offscreen framebuffer on
the screen. However, that code path works on Android only and cannot be used on a desktop.
In this recipe, we will create a wrapper for textures to make them portable.
Getting ready
Take a look at the GLTexture.cpp and GLTexture.h iles from 4_Canvas .
How to do it…
1.
Let's declare a class to hold an OpenGL texture. We need only two public operations:
loading the pixel data from a bitmap, and binding the texture to a speciied OpenGL
texture unit:
class clGLTexture
{
public:
clGLTexture();
virtual ~clGLTexture();
void Bind( int TextureUnit ) const;
void LoadFromBitmap( const clPtr<clBitmap>& B );
private:
GLuint FTexID;
GLenum FInternalFormat;
GLenum FFormat;
}
2.
The interface of the class is very simple, since textures management is almost
identical in OpenGL ES 2 and OpenGL 3. All the differences lie in the implementation.
The following code shows how we bind a texture:
void clGLTexture::Bind( int TextureUnit ) const
{
LGL3->glActiveTexture( GL_TEXTURE0 + TextureUnit );
LGL3->glBindTexture( GL_TEXTURE_2D, FTexID );
}
 
Search WWH ::




Custom Search