我一直在创建一个OpenGL程序,它将加载到OBJ文件中并将它们分组到那些组中,然后我可以将它们发送到缓冲区,但是我遇到了加载问题。
我一直在调试,它已经循环了。
为什么循环?
以下是代码:
ifstream myfile ("cubePLease.obj");
string line;
while(!myfile.eof())
{
getline (myfile,line);
//stringstream line;
if (line.compare("v") == 0)
{
glm::vec3 vertex;
(myfile,"%f %f %f\n", &vertex.x, &vertex.y, &vertex.z );
temp_vertices.push_back(vertex);
}
else if ( line.compare("vt") == 0)
{
glm::vec2 uv;
(myfile, "%f %f\n", &uv.x, &uv.y );
temp_uvs.push_back(uv);
}
else if ( line.compare("vn") == 0){
glm::vec3 normal;
(myfile, "%f %f %f\n", &normal.x, &normal.y, &normal.z );
temp_normals.push_back(normal);
}
else if ( line.compare("f") == 0)
{
std::string vertex1, vertex2, vertex3;
unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
(myfile, "%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] );
vertexIndices.push_back(vertexIndex[0]);
vertexIndices.push_back(vertexIndex[1]);
vertexIndices.push_back(vertexIndex[2]);
uvIndices .push_back(uvIndex[0]);
uvIndices .push_back(uvIndex[1]);
uvIndices .push_back(uvIndex[2]);
normalIndices.push_back(normalIndex[0]);
normalIndices.push_back(normalIndex[1]);
normalIndices.push_back(normalIndex[2]);
}
}