Loading JPG files


I am new to OPENGL and i learning it fastly.

But i have one problem :frowning: .

How can i draw a jpg file as the background picture of my window.

If anyone have enought time plz give me some code samples :slight_smile: .

Thanks in advance



You need to write your own lib for loading/decompression of jpeg files or use the one written by someone else. There is no OGL built-in ability to read these files.
Look here for some source codes: web page

And after that you can make a quad the size of your screen and apply the texture on it:
Init crap:

glGenTextures(1, &index); // generate memory for 1 texture
glBindTexture(GL_TEXTURE_2D, index); // create texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // linear magnification
glTexParameteri(GL_TEXTURE_2D,   GL_TEXTURE_MIN_FILTER, GL_LINEAR);//linear minification
// Repeat texture when value of glTexCoord2* is higher than 1.0
// no border, only one level(second argument), packed as unsigned bytes and bytes are rgba
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA mypic.width, mypic.height, GL_UNSIGNED_BYTE, GL_RGBA, mypic.texels);

Draw ****:

glBind(GL_TEXTURE_2D, index); //use texture index
glBegin(GL_QUADS); // draw a rectangle
// no repeating
glTexCoord2f(0.0, 0.0); glVertex2f(-5.0, -5.0); //lower left corner
glTexCoord2f(0.0, 1.0); glVertex2f(-5.0, 5.0); // upper left corner
glTexCoord2f(1.0, 1.0); glVertex2f(5.0, 5.0); // upper right corner
glTexCoord2f(1.0, 0.0); glVertex2f(5.0, -5.0); //lower right corner

Thanks for the valuable help

But i have some doubts about loading jpg files.

I found some example in loading BMP
using the “auxDIBImageLoad” function and stores the it in " AUX_RGBImageRec " variable.

Is any corresponding function for jpg exists?



No, there aren’t. And you shouldn’t use aux anymore, it’s really deprecated.

You can use this library (or many others) even if I personally don’t use them:


Either I’d like to add that you should not waste your time on loading many image formats. Just use one or two that suit your needs. I use SGI’s RGB one, and additionally the TGA one. They are really well documented and you can find many examples on the net on how to use them inside GL. After that any good image processor program (like Gimp or maybe Photoshop and such) will be fine to export to the formats you use.

I’m using QT for both image loading and window creating.
You might wanna look at that.


i didn;t know the detials of “SGI’s RGB one, and additionally the TGA one”. I want to have some research baout it.

Anyway i want the user selected images as my background with same clarity.



Hi Hylke Donker,


Where can i find your methods?