Home > Software engineering >  Opengl obj file open failed what reason be
Opengl obj file open failed what reason be

Time:10-23

Bool load_obj_file (const char * path, vector & The verts, vector & Faces, bool centerize=false, bool normalize=false)
{
The FILE * FILE=fopen (path, "r");
If (the file==NULL)
return false;

Float minx, miny minz, maxx, maxy, maxz;
Minx=miny=minz=maxx=maxy=maxz=0.0 f;

While (true) {
Char lineHeader [128].
Int res=fscanf (the file "% s", lineHeader);
If (EOF) res==
break;

If (STRCMP (lineHeader, "v")==0) {
Float vx, vy, vz;
Fscanf (the file "% f % f, % f \ n", & amp; Vx, & amp; Vy, & amp; Vz);
Verts. Push_back (ag);
Verts. Push_back (vy);
Verts. Push_back (vz);

Minx=min (vx, minx); Maxx=Max (vx, maxx);
Miny=min (vy, miny); Maxy=Max (vy, maxy);
Minz=min (vz, minz); Maxz=Max (vz, maxz);
}
Else if (STRCMP (lineHeader, "f")==0) {
STD: : string vertex1, vertex2 vertex3;
Unsigned int vertexIndex [3].
Int matches=fscanf (file, "% d % d % d \ n", & amp; VertexIndex [0], & amp; VertexIndex [1], & amp; VertexIndex [2]);
If (matches! {
=3)Printf (" the File format error. Both Please check the File content. \ n ");
return false;
}
Faces. The push_back (vertexIndex [0] 1);
Faces. The push_back (vertexIndex [1] 1);
Faces. The push_back (vertexIndex [2] 1);
}
The else {
Char stupidBuffer [1000].
The fgets (stupidBuffer, 1000, file);
}

}


If (centerize) {

Float cenx=0.5 f * (maxx + minx);
Float ceny=0.5 f * (maxy + miny);
Float cenz=0.5 f * (maxz + minz);


For (unsigned int I=0; i The verts [i++] -=cenx;
The verts [i++] -=ceny;
The verts [i++] -=cenz;
}
}

If (normalize) {
Float scale=1.0 f/Max (0.00001 f, Max (maxx - minx, Max (maxy - miny, maxz - minz)));
For (unsigned int I=0; i The verts [i++] *=scale;
}
}

return true;
}




Part of the initialization if (! Load_obj_file (path, _verts _faces, true, true)) {
Printf (" Error occured when initilizing the scene. ");
return;
}


Compile error: error 1 error C2143: syntax errors: lack of ";" () in front of the "constants" e: \ miniengine \ miniengine \ miniengine \ models \ cube 4 1 miniengine obj
Error 2 error C4430: lack of type specifier - is assumed to be int, note: c + + does not support default int e: \ miniengine \ miniengine \ miniengine \ models \ cube 4 1 miniengine obj


In a letter? return

CodePudding user response:

Error is not posted to you in the code

CodePudding user response:

I'm not sure the code to have write wrong, that's where wrong, environmental problems (supposedly not wrong), online said may also be a disk format problem, but don't know how to do,
That how to make qq number 1877756138, have a private talk,
  • Related