Thread: Tga

  1. #1
    Registered User
    Join Date
    Dec 2004


    I'm tired of using other people's image libraries. So I decided to write my own. I started with Bitmap files (.BMP, .ICO, & .CUR) first. It took me about an hour to finish those because it is easy to use the built in BitBlt() function. Now I'm on TGA files. I went to and found the documentation but I'm unsure exactly how to display the file. Should I convert it to a bitmap somehow? Or do i have to do a for() loop and display the bits 1 by 1? Or is there some other way? Once I figure this out the rest is easy...

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Once you have the decoded bits there are two options you can use to copy them to a windows HBITMAP. The first is to create an HBITMAP using CreateCompatibleBitmap and then copy the bits to it using SetDIBits. The other option is to create a dib section HBITMAP using CreateDIBSection. This will give you a pointer to the memory that contains the bits. You can read or decode your tga image into this memory. There is a sample of this approach here.

  3. #3
    Registered User
    Join Date
    Dec 2004

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    How do you display the other files?

    Basically, whenever you load a bitmap, you load it into an in-memory buffer which will contain raw image data in the screen-specific pixel format (RGB-24, BGR-32, Palettized-8, whatever...). Loading a TGA is not any different from the other formats: you undo any compression that may be on the image (runlength, Huffman, LZ*, JPEG-like Quantization, ...) to get the raw data in the image-specific format (that would be some palettized format for icons and cursors, GIFs, some PNGs and BMPs and others, or RGB-24 bottom-up line order for true-color BMPs, or perhaps YUV for some Adobe JPEG files, or the standard JFIF YCbCr or YCCK format). Then you transcode this format to whatever you need in the final image, which depends on your display settings, as mentioned earlier.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't Load TGA?
    By arew264 in forum Game Programming
    Replies: 9
    Last Post: 05-02-2007, 11:37 AM
  2. TGA file top-down or not?
    By pronecracker in forum Windows Programming
    Replies: 2
    Last Post: 04-16-2007, 08:21 AM
    By Mastadex in forum Windows Programming
    Replies: 2
    Last Post: 07-18-2006, 11:48 AM
  4. OpenGL; Using TGA Textures
    By cboard_member in forum Game Programming
    Replies: 6
    Last Post: 12-19-2005, 02:01 PM
  5. JPEG and TGA parser
    By xErath in forum A Brief History of
    Replies: 2
    Last Post: 10-17-2004, 04:48 PM