Using Image Files in Glut OpenGL

I am using the Glut Libraries for OpenGL in Microsoft Visual C++. One thing which I need to learn is how to display a bmp/jpg or other file type. Does anyone know a method of doing this without downloading more libs?

for bitmap file you can use glaux.h and glaux.lib
but for jpeg file you must to use other headers and libraries

glaux is buggy + can crash the app.
devil (google ‘devil openil opengl’) is an image loading library that handles nearly every image type eg jpeg,tga,png,bmp etc

but u dont want to use a librray, in that case u will have to write your own image loading code (image specs can be found at

Thank you, I found the glBitmap function, but I can’t figure out the syntax. The *bitmap parameter is a little confusing. Do I read a .bmp file into an array?

glBitmap is NOT for displaying BMP files. This assumption is a common mistake for beginners. Instead, glBitmap is used to display a true bitmap, where individual bits determine if a pixel is “on.” For example… if you have a byte with a value of 4. 4 in binary is 00000100. In this case you have 1 pixel “on” that will get drawn with the current raster color.

You can load a BMP file like this …

#include <gl/glaux.h>
// …
// Load a BMP image
AUX_RGBImageRec* LoadBMP(const char* bmpFileName)
// Enforce non-NULL filename
if (!bmpFileName)
return NULL;
// Check to see if file exists.
FILE* inFile = fopen(bmpFileName,“rb”);
if (inFile)
// It does exist, close it and let AUX load the DIB
return auxDIBImageLoad(bmpFileName);
// File does not exist
return NULL;

Note that the return value is a newly created struct that you must delete on your own (using free). It is defined as …

** RGB Image Structure

typedef struct _AUX_RGBImageRec {
GLint sizeX, sizeY;
unsigned char *data;
} AUX_RGBImageRec;

So you can load an image like this …

AUX_RGBImageRec* img = LoadBMP(“Data/Earth.bmp”);
if (img)
// Do something w/image

// Dispense of the image.

[This message has been edited by pleopard (edited 07-03-2002).]

I’m sorry if I seem slow here, but just what do I do with the img structure after I have it loaded into memory?


Thank you for your help, I have my bitmap images coming up fine now.

Sorry to bother you again…

It seems that differant programs save their bitmaps in differant styles. I can’t seem to find the correct constant for the glDrawPixels( n, n, GL_XXXX, n, * ) so that it works with MSPaint.

Does anyone know of a quick list showing which programs save their bitmaps in what format?