View Full Version : Loading JPG files
07-18-2005, 01:59 AM
I am new to OPENGL and i learning it fastly.
But i have one problem :( .
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 :) .
Thanks in advance
07-18-2005, 02:07 AM
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 (http://www.ijg.org/)
07-18-2005, 03:16 AM
And after that you can make a quad the size of your screen and apply the texture on it:
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
07-18-2005, 05:05 AM
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.
07-18-2005, 05:55 AM
I'm using QT for both image loading and window creating.
You might wanna look at that.
07-18-2005, 06:07 AM
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.
07-18-2005, 07:17 PM
Hi Hylke Donker,
Where can i find your methods?
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.