4

i have been creating a OpenGL program, which will load in a OBJ file and sort them into there groups and then i can send them to the buffers, but i am having a problem with the loading.

I have been debugging and it's going around in a loop.

Why is it is looping?

Here is the code:

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]);
    }
    }
genpfault
  • 51,148
  • 11
  • 85
  • 139
thomas
  • 67
  • 5
  • Okay this is embarrassing, i remade this from scratch and forgot the file. Sorry guys. One other problem, its reading line for line but not entering into the IF statement. when this appears for instance v 1.0 1.0 1.0 – thomas Dec 08 '15 at 11:56

0 Answers0