Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Mesh loaded with Assimp not Rendering?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    3

    Mesh loaded with Assimp not Rendering?

    I've been trying to load a 3ds model with Assimp, but once I get to the point of rendering nothing appears,
    below is the rendering code I'm trying to use due to the original not rendering for me and below that is the mesh and texture loading code. So I my question in the end would be why is it not rendering?

    Code :
    void Core::RenderMesh(const ModelInstance& inst)
    {
    ModelAsset* asset = inst.asset;
    Rendering::Program* shaders = asset->shaders;
     
    shaders->use();
     
    shaders->setUniform("camera", gCamera.matrix());
    shaders->setUniform("model", inst.transform);
    shaders->setUniform("tex", 0);
     
    glEnable(GL_VERTEX_ARRAY);
    glEnable(GL_NORMAL_ARRAY);
    glEnable(GL_TEXTURE_COORD_ARRAY);
     
    glVertexPointer(3, GL_FLOAT, 0,asset->mesh.vertexArray);
    glNormalPointer(GL_FLOAT, 0, asset->mesh.normalArray);
     
    glActiveTexture(GL_TEXTURE0_ARB);
    glTexCoordPointer(2, GL_FLOAT, 0, asset->mesh.uvArray);
     
    glBindVertexArray(asset->vao);
    glDrawArrays(GL_TRIANGLES,0,asset->mesh.numTriangles);
     
    glDisable(GL_VERTEX_ARRAY);
    glDisable(GL_NORMAL_ARRAY);
    glDisable(GL_TEXTURE_COORD_ARRAY);
     
    shaders->stopUsing();
    }

    Code :
    void Mesh::LoadMesh(std::string filename)
    {
    	Assimp::Importer importer;
    	const aiScene *scene = importer.ReadFile(filename, aiProcessPreset_TargetRealtime_Fast);
     
    	aiMesh *mesh = scene->mMeshes[0];
     
    	numTriangles = mesh->mNumFaces * 3;
    	int index = 0;
    	numUvCoords = mesh->GetNumUVChannels();
     
    	vertexArray = new float[mesh->mNumFaces * 3 * 3];
    	normalArray = new float[mesh->mNumFaces * 3 * 3];
    	uvArray = new float[mesh->mNumFaces * 3 * 2];
     
    	for (unsigned int i = 0; i < mesh->mNumFaces; i++)
    	{
    		const aiFace& face = mesh->mFaces[i];
     
    		//foreach index
    		for (int j = 0; j < 3; j++)//assume all faces are triangulated
    		{
    			aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
    			memcpy(uvArray, &uv, sizeof(float)* 2);
    			uvArray += 2;
     
    			aiVector3D normal = mesh->mNormals[face.mIndices[j]];
    			memcpy(normalArray, &normal, sizeof(float)* 3);
    			normalArray += 3;
     
    			aiVector3D pos = mesh->mVertices[face.mIndices[j]];
    			memcpy(vertexArray, &pos, sizeof(float)* 3);
    			vertexArray += 3;
    		}
    	}
     
    	uvArray -= mesh->mNumFaces * 3 * 2;
    	normalArray -= mesh->mNumFaces * 3 * 3;
    	vertexArray -= mesh->mNumFaces * 3 * 3;
    }
    Last edited by Arko4576; 01-26-2014 at 01:55 PM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,397
    I think you may have a mistaken assumption about how VAOs work. The first time, you bind them, set up your vertex array and index bindings and enables, and draw. Subsequent times, you just bind the VAO and then draw (it caches all the vertex array and index bindings and enables).

    In other words, its possible that your VAO binding right before you draw but "after" you set up your vtx/idx bindings/enables may be messing up your vertex attribute/index list bindings and enables.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    3
    You were right! I had data getting added and messing up my texture coords and vertex coords.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •