I need help loading a custom file format into my program made in c++…
I know there’s a simple way of doing this but I think I’m using the
wrong terms to search for it online…
My custom format for 3d objects is as follows:
NumVerts 6
//verts (float)
-1
-1
0
1
-1
0
-1
1
0
1
-1
0
1
1
0
-1
1
0
//texture (float)
0
0
1
0
0
1
1
0
1
1
0
1
//index (int)
0
1
2
1
3
2
And that is a quad… (yeas; I know… horrible format… but it’s what I’m using for an android game).
I want to make a function in c++ for my editor (SDL + OpenGL for windows) that loads these files into data… Unfortunately though I know how to export this format with C++, I can’t figure out how to import them… I wish to use the fstream commands…
If someone could quickly write out a simple version I’d be really thankful.
I just it to do the following:
- Find text file from input string
- read “NumVerts” and grab the integer written after it
- loop through the next (NumVerts*3) lines and grab each number as a float
- loop though the next (NumVerts*2) lines and grab each number as a float
- loop through the next (NumVerts*1) lines and grab each number as an Int
- (skip any line that starts with “//”)
- close file.
Thank you for reading and any help would be really good right now… or a relivent link that is quite simple and reads strings from files and grabs numbers from them to be placed into memory…
I really just want to finish this game and it’s getting really stressful trying to locate helpful tutorials.
Update: updated the script… I accidently forgot to seperate 1’s and 0’s…
Hope this helps. Incidentally, you have the wrong number of vertex components – you need
18of them.