Archived

This topic is now archived and is closed to further replies.

Enokh

LoadTGA function, need help

Recommended Posts

I got the TGA loader from gametutorial which works awesome for me, it can load 16, 24 and 32 bit, compressed or otherwise TGA images. It accepts a pointed to a char as the filepath for the image (like so: LoadTGA(&texture[0], "Data/Visual/Poop.tga") and so far it has worked. Now I'd like to make it so the filepath reads from a text file, along with pretty much every other paramter for the image (such as width, height, position and so on). That way I can change the values in the text file and the textured quad will appear in a different location, rotation, or whatnot. Or even just change it's texture. Later on I can add quads this way using linked lists, without recompiling the engine (modability, ease of use). It's working great so far except for the filepath part, the problem is that the function gets a char, while I can basically only input the filepath into a string. How can I convert a string to a char? Changing the LoadTGA function so that it accepts a string is not viable. Any suggestions? [edited by - Enokh on October 8, 2003 4:10:31 PM]

Share this post


Link to post
Share on other sites
Very cool, it works! Can you explain how it works please? I'm confused in the first place, before I started messing around with this perticular subject I thought that char was just a single character (like 'A') and string is an array of chars, to store words and sentances. But a char can store the word "Bah!". Also, why do we use a pointed to the char and not just the char?

Also why do we put "std::" before we declare the string?

[edited by - Enokh on October 8, 2003 5:27:12 PM]

Share this post


Link to post
Share on other sites
All that does is point to the memory address of the first "char" in your std::string

a char can''t hold "Bah!", but a char* can point to ''B''ah!\0

Sounds to me like you learned C++ and not C, which is not a bad thing, but you should at least learn pointers because that is a huge part of C\C++;

Share this post


Link to post
Share on other sites
Use string::c_str, which returns a pointer to a const char* (which can be casted to a char*). If I''m not mistaken std::string isn''t garanteed to have the characters stored contiguously in memory, which would make chbfiv''s code break if it wasn''t (which I doubt would ever happen, but you never know). Btw, it''s probably better to have the function accept a const std::string& instead of a char* because it would allow you to pass both a char* and a std::string (the std::string constructor handles that).

Share this post


Link to post
Share on other sites
Though I don''t disagree with you, and I''m just starting to use STL stuff; It was explained that most of STL is stored contiguously in memory, and if you changed the std::string, it would reallo() if needed, just for it. However, I would use what brassfish89 suggested.

Share this post


Link to post
Share on other sites