How to get this wavefront .obj data onto the frustum?

Posted by NoobScratcher on Game Development See other posts from Game Development or by NoobScratcher
Published on 2012-04-09T19:03:28Z Indexed on 2012/04/09 23:49 UTC
Read the original article Hit count: 257

Filed under:
|
|

I've finally figured out how to get the data from a .obj file and store the vertex positions x,y,z into a structure called Points with members x y z which are of type float. I want to know how to get this data onto the screen.

Here is my attempt at doing so:

//make a fileobject and store list and the index of that list in a c string
ifstream file (list[index].c_str() );

std::vector<int>faces;
std::vector<Point>points;
points.push_back(Point());
Point p;
int face[4];

while ( !file.eof() ) 
{
    char  modelbuffer[10000];
    //Get lines and store it in line string
    file.getline(modelbuffer, 10000);
    switch(modelbuffer[0])
    {
        case 'v' :
            sscanf(modelbuffer, "v %f %f %f",  &p.x, &p.y, &p.z);
            points.push_back(p);
            cout << "Getting Vertex Positions" << endl;
            cout << "v" << p.x << endl;
            cout << "v" << p.y << endl;
            cout << "v" << p.z << endl;
            break;
        case 'f':
            sscanf(modelbuffer, "f %d %d %d %d", face, face+1, face+2,  face+3 );
            cout << face[0] << endl;
            cout << face[1] << endl;
            cout << face[2] << endl;
            cout << face[3] << endl;
            faces.push_back(face[0]);
            faces.push_back(face[1]);
            faces.push_back(face[2]);
            faces.push_back(face[3]);
    }
    GLuint vertexbuffer;
    glGenBuffers(1, &vertexbuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glBufferData(GL_ARRAY_BUFFER, points.size(), points.data(), GL_STATIC_DRAW);
    //glBufferData(GL_ARRAY_BUFFER,sizeof(points), &(points[0]), GL_STATIC_DRAW);

    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
    glVertexPointer(3, GL_FLOAT, sizeof(points),points.data());
    glIndexPointer(GL_DOUBLE, 0, faces.data());
    glDrawArrays(GL_QUADS, 0, points.size());
    glDrawElements(GL_QUADS, faces.size(), GL_UNSIGNED_INT,  faces.data());
}

As you can see I've clearly failed the end part but I really don't know why its not rendering the data onto the frustum? Does anyone have a solution for this?

© Game Development or respective owner

Related posts about models

Related posts about loading