Jump to content

  • Log In with Google      Sign In   
  • Create Account

Reading in a file.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 03 September 2011 - 05:26 PM

Hi guys. I trying to do something very simple,but for some reason. When using inFile.ignore('\n'). I am not getting want I want to display. The goal here is to read in the v, vertex, vt, vertex texture, and f, faces so that I can apply some texturing later. I would like if if whenever I come across v, vt, or f, I would like to read in the values and ignoring all the other information. Does anyone have any idea? Keep it simple I am new.

You can read the .obj file using wordPad or someother text editor. I understand how to read in code, but maybe you guys know a more efficient way to extract this data.

[/file]
# Blender3D v249 OBJ File: cube.blend

# www.blender3d.org

mtllib cube.mtl

v 1.000000 -1.000000 -1.000000

v 1.000000 -1.000000 1.000000

v -1.000000 -1.000000 1.000000

v -1.000000 -1.000000 -1.000000

v 1.000000 1.000000 -1.000000

v 0.999999 1.000000 1.000001

v -1.000000 1.000000 1.000000

v -1.000000 1.000000 -1.000000

vt 0.666667 0.000000

vt 0.666667 0.333333

vt 0.333334 0.333333

vt 0.333333 0.000000

vt 0.333333 1.000000

vt 0.333334 0.666667

vt 0.666667 0.666667

vt 0.666667 1.000000

vt 0.333333 0.333333

vt 0.333333 0.666667

vt 0.000000 0.666667

vt 0.000000 1.000000

vt 0.000000 0.333333

vt 0.000000 0.000000

usemtl Material_cube_Cube.bmp

s off

f 5/1 1/2 4/3

f 5/1 4/3 8/4

f 3/5 7/6 8/7

f 3/5 8/7 4/8

f 2/2 6/7 3/9

f 6/7 7/6 3/9

f 1/10 5/5 2/11

f 5/5 6/12 2/11

f 5/9 8/13 6/4

f 8/13 7/14 6/4

f 1/10 2/11 3/13

f 1/10 3/13 4/9
[/file]



Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9668

Like
0Likes
Like

Posted 03 September 2011 - 05:29 PM

Show your code.

#3 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 04 September 2011 - 06:24 AM

Show your code.



Oh sure it is your basic code,but I have been playing around with it a little, but it looks like this. I'm really asking for tips. Many things are commented out because I have been trying different things. I would like to know if someone has an effiecient method for reading this.

void readFile() //Working section Used to count the number of floats in a file. This section can make program slower.

{

ifstream inFile;

inFile.open(
"cube.obj");

if (!inFile.is_open())

{

cout <<
"Unable to open file"; ///C:\Users\Alanzo Granville\Documents\Visual Studio 2008\Projects\Opening_A_File_Program\Opening_A_File_Program

exit(1); /// terminate with error

}

// inFile.peek() This will be the section where I peek into the file to see what is going to be read next;

int i =0;

char ch;

int num;

//Reading the first character of the file

//inFile>>ch;

//cout<<ch<<' ';

//ch = inFile.peek();

inFile>>ch;

//inFile.ignore(25,'\n');

while(!inFile.eof())

{

//ch = inFile.peek();

//inFile>>ch;

//cout<<ch<<endl;

//char ch;

//ch = inFile.peek();

//if(ch == '#')

// {

//if (i<3)

//{

//inFile.ignore(50,'\n');

// }

// if(i==3)

// ch=inFile.peek();

//cout<<" You are inside the first if statment"<<endl;



if(ch == 'v' || 't'||'f'||'/')

{

inFile>>ch;

if(ch == '0'||ch =='1'||ch =='2'||ch =='3'||ch =='4'||ch =='5'||ch =='6'||ch =='7'||

ch ==
'8'||ch =='9'||ch =='.'||ch =='-')

{

//cout<<"Did you get in"<<endl;

//inFile >> ch;// num;

//inFile>>ch;



cout<<ch<<
' ';

i++;

//inFile>>ch;

//cout << ch<<' '<<endl;

}

//else

}



//inFile.get();

//}

//inFile.get();

//floatC=i;

}//end of while loop

}



#4 pulpfist   Members   -  Reputation: 528

Like
0Likes
Like

Posted 04 September 2011 - 08:06 AM

No need to extract every byte like that unless you are writing a compiler or something.

You should be able to read and parse this file in less than 10 lines using idiomatic C++

I suggest you look into the global getline function. This function can be used to read the file line by line.

Each line (that isn't empty) can be fed to a stringstream object. This object will let you split a line into items, and convert them at the same time.
Just what you need.

Basically you extract the first item from the stringstream as a string, if that string is a 'v', you extract the next three items into some suitable variables, like floats. Conversion is implicit.

example

#5 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 05 September 2011 - 10:48 PM

No need to extract every byte like that unless you are writing a compiler or something.

You should be able to read and parse this file in less than 10 lines using idiomatic C++

I suggest you look into the global getline function. This function can be used to read the file line by line.

Each line (that isn't empty) can be fed to a stringstream object. This object will let you split a line into items, and convert them at the same time.
Just what you need.

Basically you extract the first item from the stringstream as a string, if that string is a 'v', you extract the next three items into some suitable variables, like floats. Conversion is implicit.

example



Ok I follow what you said thanks, but I am having an issue with it reading in spaces into the arrays. Any Idea on how to stop that or ignore spaces. Below is how the code looks. I have commented out alot of things, so those things can be ignored.

[/code]

void readFile() //Working section Used to count the number of floats in a file. This section can make program slower.

{

ifstream inFile;

inFile.open(
"cube.obj");

if (!inFile.is_open())

{

cout <<
"Unable to open file"; ///C:\Users\Alanzo Granville\Documents\Visual Studio 2008\Projects\Opening_A_File_Program\Opening_A_File_Program

exit(1); /// terminate with error

}

// inFile.peek() This will be the section where I peek into the file to see what is going to be read next;

int i =0;

//here we want to read in 3 different types of values,

/* 1) Declare our stringstream as stringstream ss;

2) Use a getline command to to read the entire line

ex: inFile.getline(how many items to read, string object that extracted content is stored, stops when this char is read )

inFile.get(buff, bufferSize); //(We are using this one) This implies if buff is 6, 6 items will be read, and bufferSize will store those 6 items

into some char array

or

inFile.get(buff, bufferSize, ','); //Here is similar but the last char ',' tells the comman to stop reading when it reaches a ',' comma

4)Now we need to store what is read from getline into our string stream ss.

ex:

ss << buff;

//now a for loop or while loop can be written to make sure that we read all the data from ss



ss.getline(date read into ss, number of inputs, character to discard); //This states that

ex:

ss.getline(buff, 6, ','); //Here the data read in is buff and reads 6 times, and the delimitor or stop read point is the comma which

will be discarded. Reads 6 lines

5)Now convert input value that was read in from ss into the object that we want such as int, float, char, etc using atoi function from stdlib library

ex.

suppose the variable that we want to store it in is and array called store[rows][colums] wher rows is the number of rows and colums the number of columns

store[row][column] = atoi(buff); if buff is an int, now the string data will be changed into an int object, same goes for float or char

//atof(buff) changes the data into a float

6) Then before outter loop ends or while loop ends to start again input any character into ss to do the need formating if neccessary. Then clear ss.

ex.

ss<<" "; //puts space between each character read

// now to clear. Clearing ss allows for us to read the new data that is written

ex.

ss.clear();

and results can be read out by using store[row][column]

//We are going to manipulate

1) check to see if string is v, vt, or f;

2) create conditional statemes for each one for example:

example:



//Here we may have to make stringstream ss read until it reaches a space or getline read until it reaches a space

ex:

inFile.getline(float data type, ' '); //I may have to play around with this to get it working properly. Reads till it reachs a space

if (string == 'v')

{





}*/

char ch; //buffer size

//I need to find out why my arrays cann't take other variables

int gather=1000; //buffer size

char buff[1000]; //stating that the size of the buff array is equal to gather

float vertPoint[1000][5]; //for verteices until I pass data to structs has to be global

float texPoint[1000][3];

int j=0;

//Reading the first character of the file

while(!inFile.eof())

{

inFile>>ch;

//cout<<ch<<endl;

if(ch == 'v')

{

//cout<<"You made it into the first if statment"<<endl;

inFile.getline(buff,' '); //right now this sets our buff array variabler

cout<<"This is the buff array "<<buff<<endl;

if( buff[0] == ' ') //checks the first character read in by buff to see if we have a vertex, vertex texture, or triangle face

{

//cout<<"You made it into the second if statement"<<endl;

ss<<buff; //This reads the data into the stringstream ss



vertPoint[j][i] = atof(buff);
//stringstream data that is stored in ss is given to variable point as a floating point value

cout<<vertPoint[j][i]<<endl; //line used to makes sure that I have proper output; It can be commented out

j++;

i=(i+1)%5;
//This will keep the i value between 0 to 2, while j increases with the number of vertices since it is

//storing spaces into the array



}

//I'll fix this part after I finish with the above section with storing properly in an array

if( buff[0] == 't') //checks the first character read in by buff to see if we have a vertex, vertex texture, or triangle face

{

if(buff[0] = ' ');

{

//I need to ignore the spaces readin by buff



ss<<buff;
//This reads the data into the stringstream ss

//Its not that it is reading spaces arrays are incremented like so i=1, j=1, then i=2, j=2



texPoint[j][i]= atof(buff);
//stringstream data that is stored in ss is given to variable point as a floating point value

//cout<<texPoint[j][i]<<endl; //line used to makes sure that I have proper output; It can be commented out

//j++;

//i=(i+1)%3;



}

}

}





}

/*for(i =0; i<2;i++)

{

for(j=0; j<14;j++)

{

cout<<texPoint[j][i]<<endl;

}

}*/

ss.getline(buff,'\n');

cout<<ss.str()<<endl;;
//allows me to see the entire string thats read in ouput to the screen

cout<<"Test Number "<<vertPoint[0][0]<<' '<<vertPoint[2][2]<<' '<< vertPoint[3][3]<<endl; //This is how my output is set up reads first line correctly

ss.clear(); //clears the stringstream ss

//inFile.getline(buff,2); //This read the entire line up to 1000 characters; it stops at the end of the line

//unless the line contains more than 1000 characters.

//while(!inFile.eof())//for (int i =0; i<3; i++)

//{

/*if(buff == " #")

{

ss << buff; //This stores

ss.getline(buff,1,' ');

ss<<' ';

cout<< ss.str();//<<endl; //This prints out the data read into ss from buff.

ss.clear();

}*/

//}//end of while loop

//while(!inFile.eof())

// {



//}//end of while loop

}



[/code]

[/output]
//output without all the wording
//just comment out the line of code where it says cout<<"This is the buff array "<<buff<<endl;




1
1
-1
-1
1
0.999999
-1
-1
1.000000 -1.000000 -1.000000 1.000000 -1.000000 1.000000 -1.000000 -1.000000 1.
000000 -1.000000 -1.000000 -1.000000 1.000000 1.000000 -1.000000 0.999999 1.0000
00 1.000001 -1.000000 1.000000 1.000000 -1.000000 1.000000 -1.000000 0.666667 0
.000000 0.666667 0.333333 0.333334 0.333333 0.333333 0.000000 0.333333 1.000
000 0.333334 0.666667 0.666667 0.666667 0.666667 1.000000 0.333333 0.333333
0.333333 0.666667 0.000000 0.666667 0.000000 1.000000 0.000000 0.333333 0.0
00000 0.000000
Test Number 1 -1 -1

Press any key to continue . . .

[/output]



#6 latent   Members   -  Reputation: 139

Like
0Likes
Like

Posted 06 September 2011 - 01:19 AM

Ok I follow what you said thanks, but I am having an issue with it reading in spaces into the arrays. Any Idea on how to stop that or ignore spaces. Below is how the code looks. I have commented out alot of things, so those things can be ignored.


If you're just getting stuck on parsing a delimited string, a quick google search turns up lots of results, such as
* http://www.cplusplus.com/forum/general/17771/
and if you want to use stringstream there's a few examples out there...

* http://www.dreamincode.net/forums/topic/95826-stringstream-tutorial/

Also, maybe it's just the formatting of your post, but a big function like that might only serve to confuse the matter more, especially when you come back to it later. Once you have a parsing function the process of reading the file should be very trivial and as pulpfist suggests, only take a few lines of code.






#7 pulpfist   Members   -  Reputation: 528

Like
2Likes
Like

Posted 06 September 2011 - 02:40 AM

Here is a small example of how you could get started parsing the file.
I have to admit, its going to be more than 10 lines lol.
Note that this example is far from finished.
[source lang="cpp"]void readFile(){ ifstream inFile("cube.obj"); // Create and open file if (!inFile.is_open()) { cout << "Unable to open file" << endl; exit(1); } string line, item, lib; float x, y, z; while(getline(inFile, line)) // Continue to read the next line until the end of file { stringstream ss(line); // Create a new stringstream and fill it with the line if(!(ss >> item)) // Extract the first item. If there is no items left, this expression will be false and we continue to read the next line. continue; if(item == "#") continue; // We found a comment. Continue to read the next line. else if(item == "v") { ss >> x >> y >> z; // Extract and convert the next three items from the stream cout << "We found a v: " << x << " " << y << " " << z << endl; } else if(item == "vt") { ss >> x >> y; // Extract and convert the next two items from the stream cout << "We found a vt: " << x << " " << y << endl; } else if(item == "mtllib") { ss >> lib; // Extract the next item from the stream cout << "We found a mtllib: " << lib << endl; } // And so on... }}[/source]

Since an expression like this ss >> x >> y >> z; returns false if there is less that three items left in the stream, we can take advantage of this to make the function a bit more robust:
if(!(ss >> x >> y >> z)) // report error...

Also note that the expression else if(item == "vt") is case sensitive, so it won't match a VT or a Vt.

#8 rip-off   Moderators   -  Reputation: 8726

Like
1Likes
Like

Posted 06 September 2011 - 03:39 AM

Don't keep a bunch of outdated comments in your file. Instead, use version control. This way you'll feel free to add or remove code as you like, you can always get it back the way you had it later.

The sheer number of comments is hiding things from you. For example, this line:
if(buff[0] = ' ');
{
    // code...
}
Note the semicolon after the if statement. This is treated as the following:
if(buff[0] = ' ')
{
    // Nothing to do here!
}

// code...
That is, your code is unconditionally executed.

Using fixed size buffers like you are doing is a recipe for failure - someone is either going to have a data file with lines longer than you expect, or more vertices than you catered for.

Using atof() makes it hard for you to test for failure - on failure it returns 0, which is a perfectly valid float!

Instead, use std::string and std::vector:

struct Vertex
{
    float x;
    float y;
    float z;
};

struct TexPoint
{
    float u;
    float v;
};

// TODO: more sophisticated error reporting (e.g. build a vector of struct Error { int line, SomeErrorEnumeration errorType; })
bool parseLine(const std::string &line, std::vector<Vertex> &vertices, std::vector<TexPoint> &texturePoints)
{
    if(line.empty())
    {
        return true;
    }
    
    std::stringstream stream(line);
    
    char c;
    if(!stream >> c)
    {
        return false;
    }
    
    if(c == '#')
    {
        return true;
    }
    else if(c == 'v')
    {
        if(stream.peek() == 't')
        {
            TexPoint texture;
            if((stream >> texture.u >> texture.v) && (stream >> std::ws) && stream.eof())
            {
                texturePoints.push_back(texture);
                return true;
            }
            // Failed to parse floats, or unexpected garbage at end of line
            return false;  
        }
        else
        {
            Vertex vertex;
            if((stream >> vertex.x >> vertex.y >> vertex.z) && (stream >> std::ws) && stream.eof())
            {
                vertices.push_back(vertex);
                return true;
            }
            // Failed to parse floats, or unexpected garbage at end of line
            return false;
        }
    }
    // Unhandled character
    return false; 
}

bool readFile(std::vector<Vertex> &vertices, std::vector<TexPoint> &texturePoints)
{
    std::ifstream stream("cube.obj"); 

    if(!stream.is_open()) 
    { 
        // TODO: better error notification
        cout << "Unable to open file";
        return false;
    }
    
    std::string line;
    while(std::getline(stream, line))
    {
        bool b = parseLine(line, vertices, texturePoints);
        // TODO: test b...
    }
    return true;
}
Something like that (it isn't tested).

#9 Aardvajk   Crossbones+   -  Reputation: 6189

Like
2Likes
Like

Posted 06 September 2011 - 11:55 AM

Just for future reference, from your first code, this doesn't work the way you think:

if(ch == 'v' || 't'||'f'||'/')

In english, it means: if ch equals v or if t isn't zero or if f isn't zero or if / isn't zero. Since none of the latter three are zero, the condition will always be true.

if(ch == 'v' || ch == 't' || ch == 'f' || ch == '/')

would be correct.

 else if(c == 'v')
    {
        if(stream.peek() == 't')
        {
            TexPoint texture;
            if((stream >> texture.u >> texture.v) && (stream >> std::ws) && stream.eof())

Sorry if having a senior moment, ripoff, but would you not need to consume that 't' after the peek before reading the first number?

#10 rip-off   Moderators   -  Reputation: 8726

Like
0Likes
Like

Posted 06 September 2011 - 12:51 PM

Yup, you would. As I said, untested. One could use pulpfist's suggestion of reading the first token into a string rather than peeking.

#11 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 06 September 2011 - 07:32 PM

Cube OBJ JPEG.jpg

Here is a small example of how you could get started parsing the file.
I have to admit, its going to be more than 10 lines lol.
Note that this example is far from finished.
[source lang="cpp"]void readFile(){ ifstream inFile("cube.obj"); // Create and open file if (!inFile.is_open()) { cout << "Unable to open file" << endl; exit(1); } string line, item, lib; float x, y, z; while(getline(inFile, line)) // Continue to read the next line until the end of file { stringstream ss(line); // Create a new stringstream and fill it with the line if(!(ss >> item)) // Extract the first item. If there is no items left, this expression will be false and we continue to read the next line. continue; if(item == "#") continue; // We found a comment. Continue to read the next line. else if(item == "v") { ss >> x >> y >> z; // Extract and convert the next three items from the stream cout << "We found a v: " << x << " " << y << " " << z << endl; } else if(item == "vt") { ss >> x >> y; // Extract and convert the next two items from the stream cout << "We found a vt: " << x << " " << y << endl; } else if(item == "mtllib") { ss >> lib; // Extract the next item from the stream cout << "We found a mtllib: " << lib << endl; } // And so on... }}[/source]

Since an expression like this ss >> x >> y >> z; returns false if there is less that three items left in the stream, we can take advantage of this to make the function a bit more robust:
if(!(ss >> x >> y >> z)) // report error...

Also note that the expression else if(item == "vt") is case sensitive, so it won't match a VT or a Vt.


Nice and clear code. I was looking for a way to read things in clearly. I used your code and here is the output for the v and vt portion below. But the question is how do I handle reading in the face porition of the file. All I want is the integers values and not the / or the spaces. Here is the face porition:

usemtl Material_cube_Cube.bmp

s off

f 5/1 1/2 4/3

f 5/1 4/3 8/4

f 3/5 7/6 8/7

f 3/5 8/7 4/8

f 2/2 6/7 3/9

f 6/7 7/6 3/9

f 1/10 5/5 2/11

f 5/5 6/12 2/11

f 5/9 8/13 6/4

f 8/13 7/14 6/4

f 1/10 2/11 3/13

f 1/10 3/13 4/9


Sometimes faces can also be discrible as f 1/2/3 where 1 is the vertex number, 2 is the vertex texture number, and 3 is the vertex normal.


[/code]
void readFile() //Working section Used to count the number of floats in a file. This section can make program slower.

{

ifstream inFile;

inFile.open(
"cube.obj");

if (!inFile.is_open())

{

cout <<
"Unable to open file"; ///C:\Users\Alanzo Granville\Documents\Visual Studio 2008\Projects\Opening_A_File_Program\Opening_A_File_Program

exit(1); /// terminate with error

}
string line, item, lib;

float x,y,z;

int v_Num, vt_Num, vn_Num;

while(getline(inFile, line))

{

stringstream ss(line);

if(!(ss>>item))

continue;

if(item == "#")

continue;

elseif(item == "v")

{

ss>> x>> y >>z;

cout<<
"We found a v: "<<x <<" "<<y<<" "<<z<<endl;

}

elseif(item == "vt")

{

ss >> x >> y;

cout<<
"We found a vt " <<x <<" "<<y<<endl;

}

elseif(item == "f") //faces, Here we have to read character by character from file

{

//Assuming I need a loop in the statment to finish reading the entire file



}

elseif(item =="mtllib")

{

ss>>lib;

cout<<
"We found a mtllib :" <<lib<<endl;

}

}

}


[/code]

[/output]

We found a mtllib :cube.mtl
We found a v: 1 -1 -1
We found a v: 1 -1 1
We found a v: -1 -1 1
We found a v: -1 -1 -1
We found a v: 1 1 -1
We found a v: 0.999999 1 1
We found a v: -1 1 1
We found a v: -1 1 -1
We found a vt 0.666667 0
We found a vt 0.666667 0.333333
We found a vt 0.333334 0.333333
We found a vt 0.333333 0
We found a vt 0.333333 1
We found a vt 0.333334 0.666667
We found a vt 0.666667 0.666667
We found a vt 0.666667 1
We found a vt 0.333333 0.333333
We found a vt 0.333333 0.666667
We found a vt 0 0.666667
We found a vt 0 1
We found a vt 0 0.333333
We found a vt 0 0

Press any key to continue . . .

[/output]



#12 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 06 September 2011 - 08:59 PM

Sorry for double posting, but here is something that I have got. Below is the code I wrote,but it doesn't satisfy the condition for normals since it will have two /'s instead of just one.

[/code]


elseif(item == "f") //faces, Here we have to read character by character from file

{

//Assuming I need a loop in the statment to finish reading the entire file

cout<<ss.str()<<endl;

char ch;

int v, vt;

for(i=0;i<3;i++) //reads 3 faces

{

ss>> v>>ch>>vt;

cout<<v<<
" "<<ch<<" "<<vt<<endl;

}


[/code]

[/output]

f 5/1 1/2 4/3 //This section of output is from the ss.str() function so that I can read the entire string to ensure the proper output
5 / 1 //These are the outputs which is int v =5, char ch = '/', int vt = 1 and the for loop makes it read 3 times
1 / 2
4 / 3
f 5/1 4/3 8/4
5 / 1
4 / 3
8 / 4
f 3/5 7/6 8/7
3 / 5
7 / 6
8 / 7
f 3/5 8/7 4/8
3 / 5
8 / 7
4 / 8
f 2/2 6/7 3/9
2 / 2
6 / 7
3 / 9
f 6/7 7/6 3/9
6 / 7
7 / 6
3 / 9
f 1/10 5/5 2/11
1 / 10
5 / 5
2 / 11
f 5/5 6/12 2/11
5 / 5
6 / 12
2 / 11
f 5/9 8/13 6/4
5 / 9
8 / 13
6 / 4
f 8/13 7/14 6/4
8 / 13
7 / 14
6 / 4
f 1/10 2/11 3/13
1 / 10
2 / 11
3 / 13
f 1/10 3/13 4/9
1 / 10
3 / 13
4 / 9


Press any key to continue . . .

[/output]



#13 pulpfist   Members   -  Reputation: 528

Like
0Likes
Like

Posted 07 September 2011 - 02:54 AM

Well done Posted Image

Here is a little twist I made that uses peek to find out if the vertex has a normal


char ch;
int v, vt, n;
for(int i = 0; i < 3; i++)
{				
	ss >> v >> ch >> vt;
	cout << v << " " << ch << " " << vt;				
	if(ss.peek() == '/')
	{
		ss >> ch >> n;				
		cout << " " << ch << " " << n;				
	}
	cout << endl;
}


I would also advice that you store the data in structs, and use the vector as arrays. You can see a good example of that in rip-off's post

#14 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 07 September 2011 - 08:56 AM

Just for future reference, from your first code, this doesn't work the way you think:

if(ch == 'v' || 't'||'f'||'/')

In english, it means: if ch equals v or if t isn't zero or if f isn't zero or if / isn't zero. Since none of the latter three are zero, the condition will always be true.

if(ch == 'v' || ch == 't' || ch == 'f' || ch == '/')

would be correct.

else if(c == 'v')
    {
        if(stream.peek() == 't')
        {
            TexPoint texture;
            if((stream >> texture.u >> texture.v) && (stream >> std::ws) && stream.eof())

Sorry if having a senior moment, ripoff, but would you not need to consume that 't' after the peek before reading the first number?



Yeah I agree. I am planning on string the data into structs one being struct for vertices, vertex textures, and vertex normals. then the faces will be in a struct called triangles. Thanks guys. I'll show you the results when I display the image usng OpenGL.

#15 xXDreamXx   Members   -  Reputation: 114

Like
2Likes
Like

Posted 12 September 2011 - 04:33 PM

OK guys here is the final result. The program works great. I actually built a house model and textured it. The image may be a little off since I had it rotating to check each side. Thanks so much for the help.

HouseTextureWithUVs.jpg




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS