Results 1 to 6 of 6

Thread: reading textures filenames

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Chile
    Posts
    10

    reading textures filenames

    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!

    LoadBMP(var)

    And some nice cube with MY texture appears

    Hope someone could help me
    Thanks

  2. #2
    Member Contributor
    Join Date
    Jun 2002
    Posts
    68

    Re: reading textures filenames

    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?

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    23

    Re: reading textures filenames

    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).]

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

    Re: reading textures filenames

    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!

    LoadBMP(var)

    And some nice cube with MY texture appears

    Hope someone could help me
    Thanks

  5. #5
    Member Contributor
    Join Date
    Jun 2002
    Posts
    68

    Re: reading textures filenames

    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.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Feb 2003
    Location
    Westerville, Oh, USA
    Posts
    201

    Re: reading textures filenames

    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.

Similar Threads

  1. Reading integer textures in GLSL
    By Rakehell in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-09-2016, 12:26 PM
  2. Magnified Textures & Reading Pixels
    By endlosschleife in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-01-2010, 08:27 AM
  3. Reading from 2 textures in vertex shader
    By Eirik in forum OpenGL: GLSL
    Replies: 3
    Last Post: 06-26-2009, 07:30 AM
  4. Problem reading from multiple textures
    By Handkor in forum OpenGL: GLSL
    Replies: 4
    Last Post: 05-31-2004, 08:58 PM
  5. Reading Image Formats For Use As Textures
    By Ebola in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-28-2000, 06:53 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