Firstly hello everyone, first post here :). I’ve been teaching myself OpenGL recently, mainly just experimenting with random techniques such as lighting, texturing as well as learning some of the 3D mathematics. Any problems I’ve come across I’ve fixed myself through perseverance or the all-mighty Google. This has me a bit stumped however.
The most recent thing I’ve tried is loading in and displaying models in the Wavefront OBJ format so I can start playing around with some more interesting objects. The model loads in fine yet the drawing of the model is criminally slow. I get 1 frame roughly every 8.5 seconds. The model I’m using is pretty large (2154 Vertices, 4204 Faces) but I’d guess it shouldn’t be anywhere near that slow
Since the code to load the model seems to work nice and quickly, I’ll just provide the drawing code:
void drawModel(){
vector<wavefront::WavefrontOBJFace> modelFaces = model.getModelFaces();
glEnable(GL_LIGHTING);
glBegin(GL_TRIANGLES);
//For every face in the model.
for(int i = 0; i < model.getNumberOfFaces(); i++){
float begin = glutGet(GLUT_ELAPSED_TIME);
/*
* Find the indices of the model vertices for the three
* vertices that make up the face.
*/
vector<int> vertexIndices = modelFaces.at(i).getVertexIndices();
/*
* Get the WavefrontOBJVertex object corresponding to
* each vertex in the face.
*/
wavefront::WavefrontOBJVertex vertex1 = model.getModelVertices().at(vertexIndices.at(0));
wavefront::WavefrontOBJVertex vertex2 = model.getModelVertices().at(vertexIndices.at(1));
wavefront::WavefrontOBJVertex vertex3 = model.getModelVertices().at(vertexIndices.at(2));
CVector3 coords1 = *vertex1.getCoords();
CVector3 coords2 = *vertex2.getCoords();
CVector3 coords3 = *vertex3.getCoords();
CVector3 normal1 = *vertex1.getNormal();
CVector3 normal2 = *vertex2.getNormal();
CVector3 normal3 = *vertex3.getNormal();
glNormal3f(normal1.x, normal1.y, normal1.z);
glVertex3f(coords1.x, coords1.y, coords1.z);
glNormal3f(normal2.x, normal2.y, normal2.z);
glVertex3f(coords2.x, coords2.y, coords2.z);
glNormal3f(normal3.x, normal3.y, normal3.z);
glVertex3f(coords3.x, coords3.y, coords3.z);
float end = glutGet(GLUT_ELAPSED_TIME);
std::cout << "ELAPSED TIME FOR 1 FACE: " << (end - begin) / 1000.0 << "
";
}
glEnd();
glDisable(GL_LIGHTING);
}
I’ve done a bit of scouting around and a lot of people suggest using VBOs in situations like these however I assume as far as models go, this is reasonably small and I have used another loader written by someone else that uses a similar method for storing the data and also draws the model using immediate drawing mode. The model displays perfectly fine - no slowdown at all (that loader even incorporates materials and textures - mine is only vertices and normals!). Because of this, I’m thinking that the problem lies in my drawing method but I can’t for the life of me think why.
I’m building using MinGW on Windows 7, coded in C++ using Eclipse. I’ve also tried building using Visual Studio 2010 Express and that was even slower.
Any help on this issue will be greatly appreciated, thanks.