Search code examples
androidc++opengl-esqcar-sdk

Can't draw loaded models in OpenGL ES 1.x with C++


I load obj models and try to render them with OpenGL ES using Android NDK:

class ObjModel{
public:
    ObjModel();
    ~ObjModel();

    int numVertex, numNormal,numTexCoord, numTriange;

    float *vertexArray;
    float *normalArray;
    float *texCoordArray;
    unsigned short *indexArray;

    void loadModel(string fileName);
};

model->loadModel(filename);

glVertexPointer(3, GL_FLOAT, 0,  &(model->vertexArray[0]));
glNormalPointer(GL_FLOAT, 0,  &(model->normalArray[0]));
glDrawElements(GL_TRIANGLES, model->numTriange, GL_UNSIGNED_SHORT,
                 &(model->indexArray[0]));

Model is not rendered fully, I see only part of it. I checked the data in arrays and they are parsed properly. I think that the only issue might be with passing arguments. Am I doing it right?


Solution

  • Hope this helps! I think you are just missing the number 3!

    glDrawElements(GL_TRIANGLES, 3 * model->numTriange, GL_UNSIGNED_SHORT,
                 &(model->indexArray[0]));