PDA

View Full Version : reading textures filenames



Titus
07-31-2003, 09:53 PM
Greetings:

Imagine yourself you´re using lesson06 from NeHes...
somewhere the LoadBMP function is called like this:
LoadBMP("Data/NeHe.bmp")

My problem is that my texture filename is stored in data.txt
(content of data.txt)
c:\some\thing\text1.bmp
blah
blah
blah
(EOF)

I´ve tried everything string.data(), string.c_str(), char, char* and still can make it work

All I need is to call LoadBMP with some variable that has the texture filename... and make it work! http://www.opengl.org/discussion_boards/ubb/frown.gif

LoadBMP(var)

And some nice cube with MY texture appears http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Hope someone could help me
Thanks

hkyProgrammer88
07-31-2003, 10:31 PM
Do you know how to open the file using iostream functions?

have you tried using "istream myFile;" then

myFile.open( "data.txt")

then use some looping function or procedure to read in the string. Also be sure to write checks for null files, small files and large files. And make sure your program is secure and does not crash (no buffer overflows).

However, what where you having trouble with specifically?

GlutterFly
08-01-2003, 04:32 AM
I believe for this cause the istream is the way to go.

#include <fstream>

ifstream myFile;
string fileName;

myFile.open(fileName.c_str());

/* This code will open a file associated with the string fileName, you can then referece the file through the stream!*/

I hope this helps

[This message has been edited by GlutterFly (edited 08-01-2003).]

nexusone
08-01-2003, 05:20 AM
Then you need a array variable:
would look something like this in C, note just an example some of the functions names maybe not 100% correct.

char Texture_file_list[10][30];
int files, i;

i = 0;

// First read in the file list
file = open("data.txt")
while( file != EOF )
{
getstr( file, Texture_file_list[files] );
files++;
}

// Now load the names from the file list
for( i = 0; i < files; i++)
{
LoadBMP( Texture_file_list[i] );
}



Originally posted by Titus:
Greetings:

Imagine yourself you´re using lesson06 from NeHes...
somewhere the LoadBMP function is called like this:
LoadBMP("Data/NeHe.bmp")

My problem is that my texture filename is stored in data.txt
(content of data.txt)
c:\some\thing\text1.bmp
blah
blah
blah
(EOF)

I´ve tried everything string.data(), string.c_str(), char, char* and still can make it work

All I need is to call LoadBMP with some variable that has the texture filename... and make it work! http://www.opengl.org/discussion_boards/ubb/frown.gif

LoadBMP(var)

And some nice cube with MY texture appears http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Hope someone could help me
Thanks

hkyProgrammer88
08-01-2003, 10:42 AM
Use the "getline" member function of istream to read in the texture names. And make sure your program is secure for all types of possible inputs.

starman
08-01-2003, 10:58 AM
Instead of using arrays of char strings, which are subject to buffer overflow, prefer to use vectors of strings:

#include <vector>
#include <string>

using std::vector;
using std::string;

vector<string> names;

names.push_back("name1");
names.push_back("name2");

C++ takes care of all the memory allocation/deallocation for you.