Loading JPG files

Hi,

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

Anish

Hi!

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
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// 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
glEnd();

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?

Thanks

Anish

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:

http://openil.sourceforge.net/

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.

Hai,

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.

Thanks.

Anish

Hi Hylke Donker,

Thanks.

Where can i find your methods?

regards

Anish