Download OBJ C ++ bootloader files

I created an OpenGL program that will load into an OBJ file and sort them into groups, and then I can send them to buffers, but I had a problem with loading.

I am debugging and it moves in a loop.

Why is this a cycle?

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]);
    }
    }
+4
source share

Source: https://habr.com/ru/post/1618949/


All Articles