In my game I have model loading functions for Assimp model loading library. I can load the model and render it, but the model displays incorrectly. The models load in as if they were using a seperate projection matrix. I have looked over my code over and over again, but I probably keep on missing the obvious reason why this is happening.

Here is an image of my game: Misshaped cube

It's simply a 6 sided cube, but it's off big time!

Here are my code snippets for rendering the cube to the screen:

void C_MediaLoader::display(void)
    float tmp;

    // rotate it around the y axis

    // scale the whole asset to fit into our view frustum 
    tmp = scene_max.x-scene_min.x;
    tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
    tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
    tmp = (1.f / tmp);
    glScalef(tmp/5, tmp/5, tmp/5);

    // center the model
    //glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
    // if the display list has not been made yet, create a new one and
    // fill it with scene contents
    if(scene_list == 0) {
        scene_list = glGenLists(1);
        glNewList(scene_list, GL_COMPILE);
            // now begin at the root node of the imported data and traverse
            // the scenegraph by multiplying subsequent local transforms
            // together on GL's matrix stack.
        recursive_render(scene, scene->mRootNode);

void C_MediaLoader::recursive_render (const struct aiScene *sc, const struct aiNode* nd)
    unsigned int i;
    unsigned int n = 0, t;
    struct aiMatrix4x4 m = nd->mTransformation;

    // update transform

    // draw all meshes assigned to this node
    for (; n < nd->mNumMeshes; ++n) {
        const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];


        if(mesh->mNormals == NULL) {
        } else {

        for (t = 0; t < mesh->mNumFaces; ++t) {
            const struct aiFace* face = &mesh->mFaces[t];
            GLenum face_mode;

            switch(face->mNumIndices) {
                case 1: face_mode = GL_POINTS; break;
                case 2: face_mode = GL_LINES; break;
                case 3: face_mode = GL_TRIANGLES; break;
                default: face_mode = GL_POLYGON; break;


            for(i = 0; i < face->mNumIndices; i++) {
                int index = face->mIndices[i];

                if(mesh->mColors[0] != NULL)

                if(mesh->mNormals != NULL) 


    // draw all children
    for (n = 0; n < nd->mNumChildren; ++n) {
        recursive_render(sc, nd->mChildren[n]);

Sorry there is so much code to look through, but I really cannot find the problem, and I would love to have help.

  • \$\begingroup\$ Debug it, make sure it's using the correct face_mode and check to make sure all the indices are getting added. \$\endgroup\$ – MichaelHouse Mar 28 '12 at 4:39
  • \$\begingroup\$ I've already done that, in ANY mode it has the exact same effect as seen in the image. \$\endgroup\$ – Brendan Webster Mar 28 '12 at 4:41
  • \$\begingroup\$ Really. If face_mode is set to GL_POINTS, it shows a deformed cube the the one you have in your image? \$\endgroup\$ – MichaelHouse Mar 28 '12 at 4:43
  • \$\begingroup\$ not exactly, but it does the same thing, where it is smaller and get's larger the farther it is in the z axis \$\endgroup\$ – Brendan Webster Mar 28 '12 at 4:44
  • 2
    \$\begingroup\$ It looks like you just have some really weird perspective going on. How are you setting up your view and projection matrices? \$\endgroup\$ – Jason Morales Mar 28 '12 at 8:26

Turns out this was an issue with my perspective, I was able to solve my problem by setting the gluPerspective correctly:

void C_MediaLoader::display(void)
    gluPerspective(45, 640/480,
        1.0, 1000.0);  /* Znear and Zfar */

    // remainder code is the same as before...

Thanks for everyone's help!

  • \$\begingroup\$ You should post a little more detail about how you solved the problem instead of what you have here. \$\endgroup\$ – MichaelHouse Mar 28 '12 at 18:36
  • \$\begingroup\$ OK, I just added in the extra details \$\endgroup\$ – Brendan Webster Mar 28 '12 at 18:43
  • 2
    \$\begingroup\$ I edited your post to better reflect the answer. Remember to accept your answer when you're able. \$\endgroup\$ – MichaelHouse Mar 28 '12 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.