Load and Bind Texture
Read Texture from an Image
Copy Mesh::loadMaterialTextures to your Mesh.cpp
// added in LabA07
// =====================================================
std::vector<Texture> Mesh::loadMaterialTextures(aiMaterial *mat, aiTextureType type, std::string typeName, std::string dir)
{
std::vector<Texture> textures;
// actually, we only support one texture
int nTex = mat->GetTextureCount(type);
for(unsigned int i = 0; i < nTex ; i++)
{
aiString str;
mat->GetTexture(type, i, &str);
Texture texture;
texture.id = loadTextureAndBind(str.C_Str(), dir);
texture.type = typeName;
if (texture.id > 0)
textures.push_back(texture);
}
return textures;
} Read Texture Image
Create method Mesh::loadTextureAndBind()
read texture image data with stbi_load()
Texture Setup
Generate textureId
Bind texture and generate Mipmap in OpenGL
Set OpenGL texture parameters
Free image data and return textureid
Full Source Code of Mesh::loadTextureAndBind()
Last updated