Jump to content
  • Advertisement
Sign in to follow this  
MyNiceDisplayName

OpenGL Problem with texturing using Assimp (C++/OpenGL)

This topic is 1469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Recently I've been following some turorials trying to learn how to import textured 3D models using Assimp.

I am now able to load and display (single- or multitextured) 3D models, in both .obj and .m2d format.
However, there are some models I am not able to display properly, such as this one: http://static.tf3dm.com/models/3dregenerator/Game%20Packs/Final%20Fantasy%20X/FFX%20Tidus.7z
I can load it using Blender, but when I try to ty display it using my program, it looks like this:
ModelT.png

AssimpViewer.exe also fails to load it (the program crashes) so I was hoping I could blame assimp for it, but when I checked the data loader aiScene in my program it seemed like it had imported all textures and texture coords properly.

(I have uploaded my  class header file together with this post, in case you want to see the whole code).

Basically, what I do is to load the vertices, indices and texture coordinates from each aiMesh into some buffers, and display it using glDrawElements:
 

for (MeshEntry mesh : meshEntries) {    

            // VBO
            glEnableVertexAttribArray(0);
            glBindBuffer(GL_ARRAY_BUFFER, mesh.VBO);
            glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
        
            // TBO
            glEnableVertexAttribArray(2);
            glBindBuffer(GL_ARRAY_BUFFER, mesh.TBO);
            //glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)20);
            glTexCoordPointer(3, GL_FLOAT, 0, 0);
            glBindTexture(GL_TEXTURE_2D, textures[mesh.materialIndex]);

            // Bind indices
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.IBO);

            glDrawElements(GL_TRIANGLES, mesh.indices * 3, GL_UNSIGNED_INT, 0);

        }
        SDL_GL_SwapWindow(mainWindow);

VBO = Vertex buffer
TBO = Texture buffer
IBO = Index buffer

This works perfectly fine for most 3D models I try to load, but not for all.
All 3D models that I have failed to display properly until now, also made AssimpViewer crash.
Any suggestion what I am doing wrong?

(If the above link doesn't work, you can download the model from here: http://tf3dm.com/download-page.php?url=tidus-77545)

Share this post


Link to post
Share on other sites
Advertisement

If AssimpViewer also fails to load the model then it suggests there is something within the model that assimp cannot work with. 

 

One more test would be to use Open3Mod which is the new viewer that assimp provides and see if it works in that. ( I've had some models that work in one but not the other )

 

Although assimp manages to load the model into the aiScene I'm guessing there is some portion of the data that is incorrect. Have you tried rendering the model without any textures? i.e. just using one colour. If this works which it probably will looking at the image you provided then I would think it is probably something to do with the Textures or Texture Co-ordinates being incorrect on the model. 

 

Hope this helps.

Share this post


Link to post
Share on other sites

If AssimpViewer also fails to load the model then it suggests there is something within the model that assimp cannot work with. 

 

One more test would be to use Open3Mod which is the new viewer that assimp provides and see if it works in that. ( I've had some models that work in one but not the other )

 

Although assimp manages to load the model into the aiScene I'm guessing there is some portion of the data that is incorrect. Have you tried rendering the model without any textures? i.e. just using one colour. If this works which it probably will looking at the image you provided then I would think it is probably something to do with the Textures or Texture Co-ordinates being incorrect on the model. 

 

Hope this helps.

Thank you, you are absolutely right! It was the textures.

After reading your comment, I checked the IMG_Load function once more:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->w, surface->h, 0, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
As you see, this will only work for GL_RGB. I simply changed GL_RGB to GL_RGBA(when image is 32bit), and now it's displaying the 3D model perfectly.

Thank you for recommending me Open3Mod. I will be using that one from now on : )

Share this post


Link to post
Share on other sites

Glad I could help :)

 

yeah Open3Mod is pretty good, although I wouldn't get rid of assimpViewer as it lets you toggle the import flags which open3Mod doesn't fully allow you to.

 

Open3Mod is much better for looking at the details of the scene hierarchy nodes. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!