View Full Version : Using Image Files in Glut OpenGL

07-02-2002, 07:56 PM
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?

07-02-2002, 10:17 PM
for bitmap file you can use glaux.h and glaux.lib
but for jpeg file you must to use other headers and libraries

07-02-2002, 10:27 PM
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 www.worsit.org) (http://www.worsit.org))

07-03-2002, 03:51 AM
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?

07-03-2002, 05:39 AM
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.

07-03-2002, 07:03 AM
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).]

07-03-2002, 02:35 PM
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?

07-04-2002, 02:35 AM

07-04-2002, 05:23 AM
Thank you for your help, I have my bitmap images coming up fine now.

07-04-2002, 05:51 AM
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?