Results 1 to 7 of 7

Thread: basic texture loading in glut

  1. #1
    Guest

    basic texture loading in glut

    excuses for just how basic this is, i'm currently just learning openGL at university and it turns out that there's not enough time for them to teach us texturing

    i've looked around and i think i'd be comfortable using a texture but i'm really unclear as to how you load one.....i'm using glut because our programs have to be platform independant

    i think i have to make a BMPLoad or TGALoad function but what are the advantages of the two file formats? and can anyone point me in the direction of how to load a file and store it for use as a texture? (without using auxDIBImageLoad)

    thanks in advance

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    108

    Re: basic texture loading in glut

    nehe has a tutorial on loading tga files nehe.gamedev.net

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2011
    Posts
    150

    Re: basic texture loading in glut

    I've used the Image Format Library for Windows and IRIX. I haven't found a version for Linux yet. IFL supports many formats (e.g. TIFF, GIF, PNG, JFIF(JPEG), SGI, BMP, raw formats, etc.). See http://www.sgi.com/products/evaluation/pc_ifl_1.3.1/.

    I've also written a cross-plaform image loader for SGI formats (e.g. INT, INTA, RGB, RGBA). I'll send it to you with example if you email me at b*r*cain@yahoo.com (remove *).

    I've also wondered if there are GIMP libraries available. But, I haven't looked into it yet.

  4. #4
    Member Contributor
    Join Date
    Nov 2001
    Posts
    77

    Re: basic texture loading in glut

    Bitmap and Targa images are almost identical in the way they store data. The only advantage between them is Targa images can carry with it an additional alpha channel, which allows for some neat blending effects. Anyway, the idea for loading them is:

    1) open the file
    2) load important data from the file (height, width, bpp, etc.)
    3) skip to the data (always at the end of the header info)
    4) copy the data to memory
    5) switch red and blue values
    6) use data as a texture

    Step 5 will give you headaches until you really understand it. Bitmap and Targa files store pixel data in the sequence BGR or BGRA (blue, green, red, alpha), but OpenGL wants the data in the form RGB or RGBA (red, green, blue, alpha.) There are two ways around this: you can convert it yourself, or tell OpenGL to. The latter is less reliable since some systems will not have extension necessary to understand BGR and BRGA formats. Also, be wary of different pixel formats. For example, 15 bit color stores a pixel as one short value, where the highest bit is never used, and the lower bits are blue, green, and red (5 bits each). Using this format will only work on little endian systems. On big endian systems, the short will come in like this: gggrrrrr 0bbbbbgg, where each letter represents a bit of the color. You'll have to swap the dat around to reach 0bbbbbgg gggrrrrr format. This is becoming really complicated, but if you need platform independance, it's unfortunately necessary.

    Even with all of these ideas, it's not hard to write a bitmap and/or targa file loader:

    1) check endian-ness:
    in C:
    Code :
    #define LITTLE_ENDIAN 0
    #define BIG_ENDIAN 1
    int GetEndian()
    {
      unsigned long value=0x12345678;
      unsigned char *ptr =(char *)&value;
      if (ptr[0]==0x12) return BIG_ENDIAN;
      return LITTLE_ENDIAN;
    }
    2) load file
    3) get important information (include palette for 8 bit files)
    4) allocate necessary memory
    5) load one pixel worth of data:
    8 bit color = 1 char
    15 bit color = 1 short*
    16 bit color = 1 short*
    24 bit color = 3 chars
    32 bit color = 4 chars OR 1 long*
    6) if data type is order specific (*), and system is big endian, swap byte order
    7) swap red and blue values (can be tricky in 15/16 bit formats)
    store pixel in data
    9) repeat from step 4 until end of file or end of allocated memory reached
    10) close file
    11) use data as texture

    That's the only way I know of to load an image file AND maintaining platform independence.

  5. #5
    Guest

    Re: basic texture loading in glut

    i read nehe, it was kinda my main source of information but it uses auxDIBImageLoad which has apparently vanished from glaux

    thanks for the link brcain, the thing is that i don't want to rely on libraries or APIs to do things for me.....sorry if i sound arsey but i'd prefer to do it all myself.....the work will eventually end up in coursework and they generally frown on using anything more than glut............it is appreciated though, im downloading it and will have a good look through it in a bit

    ok, i read what you wrote Nychold about five times......i think i get the concept now (i'm a bit slow)......it makes sense and is hugely appreciated, thanks......i'll go and read up on file formats, since i'll be making the textures i guess i can use 24bpp and get basic functionality for the time being

    thanks to all, this is a great help

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: basic texture loading in glut

    Nehe also has a TGA loading routine which is not part of any library. Not sure the lesson number but it is in the 30's.

    Also you can go a google search on the TGA file format, and write your own routine to load a TGA or BMP.

    I have a glut example with a TGA file loader, for loading a texture on my website, www.angelfire.com/linux/nexusone/




    [This message has been edited by nexusone (edited 02-19-2004).]

  7. #7
    Guest

    Re: basic texture loading in glut

    ah sweet....thank you, i just got a file format book from the library so i'm all set i think

Similar Threads

  1. Basic OpenGL Model loading
    By Menta2K in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-30-2014, 06:54 PM
  2. Implement Basic File Loading Into OpenGL's Standard.
    By Knight Chat X in forum OpenGL: General
    Replies: 21
    Last Post: 10-22-2012, 05:51 PM
  3. Basic Glut Help
    By monkfish in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-07-2005, 08:47 AM
  4. Loading 3d models in Visual Basic
    By NauticalJustin in forum OpenGL: User Software
    Replies: 0
    Last Post: 11-18-2003, 08:04 AM
  5. Basic Inventor/glut-examples wanted.
    By RatKing in forum OpenGL: General
    Replies: 1
    Last Post: 10-17-2000, 04:19 AM

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