Skip to content

Commit

Permalink
Add textures to renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyDaSilva committed Feb 22, 2016
1 parent b8660ea commit 1d57951
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ Model::recursiveTextureLoad(const struct aiScene *sc, const aiNode* nd)

// See if another mesh is already using this texture, if so, just copy GLuint instead of remaking entire texture
bool newTextureToBeLoaded = true;
for (int x = 0; x < texturesAndPaths.size(); x++)
for(std::map<std::pair<const aiNode*, int>, TextureAndPath>::iterator it = texturesAndPaths.begin(); it != texturesAndPaths.end(); ++it)
{
if (texturesAndPaths[x].pathName == *str)
if(it->second.pathName == *str)
{
TextureAndPath reusedTexture;
reusedTexture.hTexture = texturesAndPaths[x].hTexture;
reusedTexture.hTexture = it->second.hTexture;
reusedTexture.pathName = *str;
texturesAndPaths.push_back(reusedTexture);
texturesAndPaths[std::make_pair(nd, n)] = reusedTexture;
newTextureToBeLoaded = false;

std::cout << "Texture reused." << std::endl;
Expand Down Expand Up @@ -130,7 +130,7 @@ Model::recursiveTextureLoad(const struct aiScene *sc, const aiNode* nd)

std::cout << "texture loaded." << std::endl;

texturesAndPaths.push_back(newTexture);
texturesAndPaths[std::make_pair(nd, n)] = newTexture;
}
}
}
Expand Down Expand Up @@ -199,10 +199,11 @@ Model::recursive_render(const struct aiScene *sc, const aiNode* nd) const
// draw all meshes assigned to this node
for (; n < nd->mNumMeshes; ++n)
{
glEnable(GL_TEXTURE_2D);
const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];

if (n < texturesAndPaths.size())
glBindTexture(GL_TEXTURE_2D, texturesAndPaths[n].hTexture);
glBindTexture(GL_TEXTURE_2D, texturesAndPaths.at(std::make_pair(nd, n)).hTexture);

apply_material(sc->mMaterials[mesh->mMaterialIndex]);

Expand Down
3 changes: 2 additions & 1 deletion src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <FreeImage.h>
#include <vector>
#include <map>

#include <iostream>

Expand All @@ -54,7 +55,7 @@ struct TextureAndPath
class Model
{
private:
std::vector<TextureAndPath> texturesAndPaths;
std::map<std::pair<const aiNode*, int>, TextureAndPath> texturesAndPaths;
const struct aiScene* scene;

void
Expand Down

0 comments on commit 1d57951

Please sign in to comment.