EasyBMP C++ Bitmap Library

EasyBMP Extensions: OpenGL

This extension to EasyBMP provides some basic interfaces to OpenGL.

Click here to download the extension. (Contained in the extensions package)

This extension allows you to convert BMP objects to textures that OpenGL can use for texture mapping, etc. Because the width and height of an OpenGL texture must be multiples of 2, the extension will automatically pad the texture with white pixels such that it fits in a 2n x 2n square.

Within the texture, the coordinates (x,y) gives a point x from the left and y from the bottom of the texture. Note that (0,0) gives the bottom left corner and (1,1) gives the top right corner of the image. The data members MaxX and MaxY give the coordinates of the edge of the original image within this padding.

class EasyBMP_Texture
 GLubyte* Texture; // an OpenGL-compatible array of bytes for the texture
 int Width; // width of the texture
 int Height; // height of the texture
 GLfloat MaxX; // max x coordinate of the texture
 GLfloat MaxY; // max y coordinate of the texture
 EasyBMP_Texture(); // creates an empty texture
 ~EasyBMP_Texture(); // leanup (don't use this)
 int TellWidth( void ); // tells the width of the texture
 int TellHeight( void ); // tells the height of the texture
 void SetSize( int NewWidth, int NewHeight ); // resizes the texture
 void ImportBMP( BMP& InputImage ); // imports and converts a BMP object

Here is a sample application:

#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include <windows.h>

#include "EasyBMP.h"
#include "EasyBMP_OpenGL.h"

#include <cstdlib>
#include <cstdio>

using namespace std;

static GLuint texName;
GLubyte* Texture;
EasyBMP_Texture BMPtexture;

void display( void )

 GLfloat MaxX = BMPtexture.MaxX;
 GLfloat MaxY = BMPtexture.MaxY;

 GLfloat Width = MaxX*4;
 GLfloat Height = MaxY*4;


  glTexCoord2f(0,0) ; glVertex3f(0,0,0);
  glTexCoord2f(MaxX,0); glVertex3f(Width,0,0);
  glTexCoord2f(0,MaxY); glVertex3f(0,Height,0);



void reshape(int w,int h)
 glViewport(0,0,(GLsizei) w,(GLsizei) h);
 gluPerspective(60,(GLfloat) w/(GLfloat) h, 1,30);

void init( void )

 BMP Temp;
 Temp.ReadFromFile( "nixon.bmp" );
 BMPtexture.ImportBMP( Temp );


 glBindTexture(GL_TEXTURE_2D, texName );


 0,GL_RGBA,GL_UNSIGNED_BYTE, BMPtexture.Texture );

int main( int argc, char* argv[] )


 return 0;

Here's how to compile it using mingw in Windows:

g++ -o easybmp_opengl easybmp_opengl.cpp -lopengl32 -lglut32 -lglu32

The result should be the image nixon.bmp on a black background.