Hello
I am writing an OBJ loader for OpenGL ES. What am I doing worng? loadModel is called once, while drawModel is called 25 times per second.
bool SFModel::loadModel()
{
…
parsing obj data
…
// Load textures
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
texture = (GLuint*)malloc(sizeof(GLuint)*materials.count());
glGenTextures(materials.count(), texture);
for (int i=0; i<materials.count(); i++)
{
QString materialFile = “data/” + materials[i].remove(0,1);
QImage image;
if (image.load(materialFile, “PNG”))
{
QImage matImage = QGLWidget::convertToGLFormat( image );
glBindTexture(GL_TEXTURE_2D, texture[i]);
glTexImage2D( GL_TEXTURE_2D, 0, 3,
matImage.width(), matImage.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, matImage.bits() );
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
qDebug(“Cannot load image from file %s”, materialFile.toAscii().data());
}
}
// Define vertices, normals and textcoords
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, textureVertices);
return true;
}
void SFModel::drawModel()
{
glPushMatrix();
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Draw faces
for (uint i = 0; i < numFaces; i++)
{
glBindTexture( GL_TEXTURE_2D, texture[faces[i].material] );
glNormal3f( normals[faces[i].nindices[0]-1].x(),
normals[faces[i].nindices[0]-1].y(),
normals[faces[i].nindices[0]-1].z() );
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT,
faces[i].vindices);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
Thank you very much