Thread: Can't Load TGA?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    Can't Load TGA?

    I am making a 2d rts game, and while I am pretty knowledgable about setting up client/server gunk and that sort of thing, I have no experience with graphics. Searching around, I decided to go with SDL as it seems to be about what I want/need and should perform pretty well.

    So far I have hit one major snag, the snag being that I can't load a TGA image to a SDL surface (OMG I feel like an idiot ).
    My thought was to keep it as simple as possible starting out, so I downloaded the latest SDL Image library, grabbed their function to load a TGA, and dropped it and everything it requires in. I only get two errors, and those two I believe are not errors in putting in the code.
    The errors are both "error: invalid conversion from 'void*' to 'Unit8*'
    They appear on lines 206 and 250 of IMG_tga.cpp.
    I hesitate to post the source up because it's pretty dang long (hoping to catch someone else that uses SDL). If I need to, let me know (I probably do).

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I had a really hard time getting SDL_Image to work. You either compile it yourself as you seem to be doing, for which you need lots of extra libraries such as libjpeg; or you use a .lib, which doesn't work too well with Dev-C++.

    But it looks like you're compiling C code as C++, judging from the error. This is valid C, but not valid C++:
    Code:
    Uint8 *x = 0;
    void *p = x;
    Uint8 *y = p;
    In C++ you need
    Code:
    Uint8 *y = (Uint8 *)p;
    So I suggest you either compile it as C code or add casts like those above.

    Also, why are you using the TGA format? I'm just curious, because I've never really used it myself. I usually go with PNG.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    7
    Thank you!
    I'm going with TGA because it has transparency and it has basically no compression, so it is very high quality. It's also a bit of a personal preference.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by arew264 View Post
    Thank you!
    I'm going with TGA because it has transparency and it has basically no compression, so it is very high quality. It's also a bit of a personal preference.
    I usually use PNG and JPEG. PNG is a lossless format, so it's quality is the best possible. JPEGs are lossy, so you get to choose how high the quality is, but they tend to be smaller for photographs. PNG supports transparency, JPEG does not.

    PNG was originally created as a free replacement for GIF, but I find PNG is great for almost everything, except for very large photographs.

    But if TGA is your personal preference then what can I say?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by arew264 View Post
    Thank you!
    I'm going with TGA because it has transparency and it has basically no compression, so it is very high quality. It's also a bit of a personal preference.
    It's also brain-dead simple to read and write it. For one-offs I tend to go with PNM-type formats, but that's not such a good choice on Windows since few utilities understand it there.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    7
    One other thing I might recommend - you mentioned Dev-C++. Ever tried Code::Blocks? Good stuff.... I don't mean to start a war here, but you might try the nightly. It works pretty well.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by brewbuck View Post
    It's also brain-dead simple to read and write it.
    Indeed. I love this graphics file format.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by dwks View Post
    I usually use PNG and JPEG.
    How so? Do you use libpng and libjpeg? Don't you just hate how those libraries use longjmp() for error handling?

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by brewbuck View Post
    How so? Do you use libpng and libjpeg? Don't you just hate how those libraries use longjmp() for error handling?
    I've never actually used libpng or libjpeg directly -- though I have compiled them, so I know what you mean with the heavy use of setjmp.h. I just like using PNGs for the web; and I use them in programs with SDL_Image. And photos work quite well as JPEGs.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    I like .png, mainly because it's small. However, TGA would seem to be a better format, as it is more widely used, and you can also load the images yourself, without having to rely on external shared libraries.

    However, as dwks said, its a matter of personal preference.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File send app - md5 checksum different when load is put on server.
    By (Slith++) in forum Networking/Device Communication
    Replies: 5
    Last Post: 12-31-2007, 01:23 PM
  2. How to load .obj files?
    By h3ro in forum Game Programming
    Replies: 4
    Last Post: 05-14-2007, 05:27 AM
  3. Just finished assembly assignment
    By xddxogm3 in forum Tech Board
    Replies: 6
    Last Post: 10-08-2005, 04:01 PM
  4. Opera 8.50 - Now free!
    By BMJ in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 09-29-2005, 07:10 AM
  5. How can I load a cpu a certain percentage?
    By Smartiepants586 in forum C Programming
    Replies: 4
    Last Post: 06-07-2005, 12:15 PM