I'm trying to read from a file following this tutorial: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/
The problem is that when I try to copy the code and do fscanf, the values are always initialized to crazy values like -848228281 or something similar. The first time I read the values for the vertices it works, but not for the faces.
while (!(feof(fp)))
{
read = fscanf(fp, "%c", &ch);
if (/*read == 4 && */ch == 'v')
{
// this works
read = fscanf(fp, "%f %f %f\n", &x, &y, &z);
vertices.push_back(vector3(x, y, z));
//glVertex3f(x, y, z);
}
else if (ch == 'f')
{
GLint vertexIndex[3], uvIndex[3], normalIndex[3];
// this line below does not work
int matches = fscanf(fp, "%d/%d/%d %d/%d/%d %d/%d/%d\n",
&vertexIndex[0], &uvIndex[0], &normalIndex[0],
&vertexIndex[1], &uvIndex[1], &normalIndex[1],
&vertexIndex[2], &uvIndex[2], &normalIndex[2]);
if (matches != 9)
{
printf("Incompatible file!");
return;
}
}
}
My obj file is the same as in the tutorial.