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.
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 specified 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; }
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...