Results 1 to 8 of 8

Thread: Loading JPG files

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2005
    Location
    India
    Posts
    11

    Loading JPG files

    Hi,

    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

    Anish

  2. #2
    Member Newbie
    Join Date
    Nov 2003
    Location
    Gliwice, Slaskie, Poland
    Posts
    45

    Re: Loading JPG files

    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

  3. #3
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: Loading JPG files

    And after that you can make a quad the size of your screen and apply the texture on it:
    Init crap:
    Code :
    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 ****:
    Code :
    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();

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2005
    Location
    India
    Posts
    11

    Re: Loading JPG files

    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

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Loading JPG files

    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.

  6. #6
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: Loading JPG files

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

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2005
    Location
    India
    Posts
    11

    Re: Loading JPG files

    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

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2005
    Location
    India
    Posts
    11

    Re: Loading JPG files

    Hi Hylke Donker,

    Thanks.

    Where can i find your methods?

    regards

    Anish

Similar Threads

  1. Loading 3DS files
    By dslprog in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-12-2004, 07:23 AM
  2. Loading X 3d files: How? Where can I get this?
    By Schlogenburg in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 01-02-2003, 12:39 PM
  3. Loading .dxf files
    By VenTure in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-11-2000, 08:00 AM
  4. Loading .mdl files
    By codemaster in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-09-2000, 11:55 PM
  5. loading RAW files / general model loading question
    By tcs in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-23-2000, 12:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean