Basic Use

This little guide should get you started. Important items are strong.

Example

That whole thing might look something like this (code involving glbmp is strong):

#include <stdio.h>

#include <GL/gl.h>
#include "glbmp.h"

...

/* Loads the specified bitmap file from disk and copies it into an OpenGL texture.
 * Returns the GLuint representing the texture (calls exit(1) if the bitmap fails to load).
 */
GLuint LoadTexture(const char * bitmap_file)
{
   GLuint texture = 0; //OpenGL texture to create and return
   glbmp_t bitmap;     //object to fill with data from glbmp

   //try to load the specified file--if it fails, dip out
   if(!glbmp_LoadBitmap(bitmap_file, 0, &bitmap))
   {
      fprintf(stderr, "Error loading bitmap file: %s\n", bitmap_file);
      exit(1);
   }

   //generate and bind the OpenGL texture
   glGenTextures(1, &texture);
   glBindTexture(GL_TEXTURE_2D, texture);

   //copy data from bitmap into texture
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
                0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);

   //set up texture filtering
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   //free the bitmap
   glbmp_FreeBitmap(&bitmap);

   return texture;
}

...

void SomeInitFunction(void)
{
   GLuint tex1;
   ...
   tex1 = LoadTexture("texture1.bmp");
   ...
}

glaux Replacement

Here is everything you need to do to remove all that pesky glaux code. Differences in each line are strong.

Change To
#include <GL/glaux.h> #include "glbmp.h"
AUX_RGBImageRec * img; glbmp_t bitmap;
img = auxDIBImageLoad("some.bmp"); glbmp_LoadBitmap("some.bmp", 0, &bitmap)
glTexImage2D(GL_TEXTURE_2D, 0, 3, img->sizeX, img->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, img->data); glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);
free(img->data); free(img); glbmp_FreeBitmap(&bitmap);

You'll also obviously have to adjust your error handling code appropriately. For example:

Change To
img = auxDIBImageLoad("some.bmp");
if(!img)
{
   //error
}

if(!glbmp_LoadBitmap("some.bmp", 0, &bitmap))
{
   //error
}

Further Information

For more information about how to use glbmp, just look in the header. Everything you need to know (such as semantics of the function calls) is in there.

Also, check out the glbmp webpage: http://chaoslizard.sourceforge.net/glbmp/.

This document was written by the author of glbmp, Charles Lindsay. I can be reached at charles [at] chaoslizard [dot] org with questions, bug reports, and so on. While I intend for this document to be useful, I make no claims about the validity of any information here.