I can't access why and how this code is not outputing the right results and if this is the best way to .obj file parsing with c++ since ".c_str()"?
So far it gets the filename and opens it up with ifstream then checks if the ifstream opened up good
then it gets the lines and checks with strstr if the char array contains a v and space "v "
if it does then sscanf the char array "c-string" at that position "I suppose" for the format number.number number number.
However even that format specifier is wrong I think... but it's all so confusing to me.
The documentation writes "..." for this parameter of sscanf(const char * char, const char *format , ...);
Here is the code :
void OpenGL::LoadObj(const char * objfile)
{
std::ifstream objstream(objfile);
std::string objfiletext;
int value[3];
while(objstream.good())
{
std::getline(objstream, objfiletext);
if(strstr(objfiletext.c_str(), "v "))
{
sscanf(objfiletext.c_str(), "%d.%d %d %d", value[0], value[1], value[2], value[3]);
std::cout << value[0] << value[1] << value[2] << std::endl;
}
}
}
public member function usage :
GLrenderer.LoadObj("cube.obj");
CONSOLE OUTPUT :
3414949232
3414949232
3414949232
3414949232
3414949232
3414949232
3414949232
3414949232
CUBE.OBJ :
# Blender v2.74 (sub 0) OBJ File: ''
# www.blender.org
o Cube
v 1.500000 -1.000000 -1.000000
v 1.500000 -1.000000 1.000000
v -1.500000 -1.000000 1.000000
v -1.500000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
s off
f 2 3 4
f 8 7 6
f 5 6 2
f 6 7 3
f 3 7 8
f 1 4 8
f 1 2 4
f 5 8 6
f 1 5 2
f 2 6 3
f 4 3 8
f 5 1 8
Please don't tell me to use a library like assimp , I wanna do this all by myself thank you.