本文整理汇总了C++中TextureLoader::loadTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ TextureLoader::loadTexture方法的具体用法?C++ TextureLoader::loadTexture怎么用?C++ TextureLoader::loadTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextureLoader
的用法示例。
在下文中一共展示了TextureLoader::loadTexture方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: string
vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial* mat,
aiTextureType type,
TextureTypes texType) {
TextureLoader textureLoader;
vector<Texture> textures;
for(GLuint i = 0; i < mat->GetTextureCount(type); i++) {
aiString str;
mat->GetTexture(type, i, &str);
GLboolean skip = false;
for(GLuint j = 0; j < textureCache.size(); j++) {
if(textureCache[j].path == string(str.C_Str()))
{
textures.push_back(textureCache[j]);
skip = true;
break;
}
}
if(!skip) {
std::string filepath = directory + '/' + string(str.C_Str());
Texture texture = textureLoader.loadTexture(filepath,
texType);
texture.path = string(str.C_Str());
textures.push_back(texture);
this->textureCache.push_back(texture);
}
}
return textures;
}
示例2: string
vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial* mat,
aiTextureType type,
TextureTypes texType) {
TextureLoader textureLoader;
vector<Texture> textures;
for(GLuint i = 0; i < mat->GetTextureCount(type); i++) {
aiString str;
mat->GetTexture(type, i, &str);
string filename = string(str.C_Str());
/*
// <Eagle HASK> :(
string filenameTMP = string(str.C_Str());
string filename = "";
for(int i = 4; i < filenameTMP.size(); i++){
if(filenameTMP[i] == '\\')
filename += "/";
else
filename += filenameTMP[i];
}
// </Eagle HASK> :(
*/
GLboolean skip = false;
for(GLuint j = 0; j < textureCache.size(); j++) {
if(textureCache[j].path == filename)
{
textures.push_back(textureCache[j]);
skip = true;
break;
}
}
if(!skip) {
std::string filepath = directory + '/' + filename;
Texture texture = textureLoader.loadTexture(filepath,
texType);
texture.path = string(str.C_Str());
textures.push_back(texture);
this->textureCache.push_back(texture);
}
}
return textures;
}
示例3: loadHeightmap
void Heightmap::loadHeightmap(string filename, float strength) {
TextureLoader tl;
Texture t = tl.loadTexture(filename, 1);
if(t.getWidth() < columns || t.getHeight() < rows) {
cout << "The provided file " << filename << " (" << t.getWidth() << "x" << t.getHeight() << ") is too small and cannot be used for this heightmap (" << columns << "x" << rows << ")" << endl;
return;
}
int dx = t.getWidth()/columns;
int dy = t.getHeight()/rows;
for(int row = 0; row <= rows; row++) {
for(int column = 0; column <= columns; column++) {
setHeightAt(column, row, (t.getData()[row * t.getWidth() * dy + column * dx] / 255.0f) * strength);
//assert(0.0f <= getHeightAt(column, row) && getHeightAt(column, row) <= strength);
}
}
calculateNormals();
}
示例4: loadDuckModel
Model DuckLoader::loadDuckModel() {
vector<Vertex> vertices;
vector<GLuint> indices;
string filepath = "res/models/duck/duck.txt";
ifstream fileStream(filepath);
if(!fileStream){
throw new invalid_argument("No such duck file");
}
string line;
getline(fileStream, line);
int vertexCount = stoi(line);
for(int i = 0; i < vertexCount; i++){
getline(fileStream, line);
vector<string> vertexStr = splitString(line, " ");
if(vertexStr.size() != 8){
throw new invalid_argument("No such duck file");
}
vec3 pos = vec3(atof(vertexStr[0].c_str()),
atof(vertexStr[1].c_str()),
atof(vertexStr[2].c_str()));
vec3 norm = vec3(atof(vertexStr[3].c_str()),
atof(vertexStr[4].c_str()),
atof(vertexStr[5].c_str()));
vec2 tex = vec2(atof(vertexStr[6].c_str()),
atof(vertexStr[7].c_str()));
Vertex vertex;
vertex.Position = pos;
vertex.Normal = norm;
vertex.TexCoords = tex;
vertices.push_back(vertex);
}
getline(fileStream, line);
int indexCount = stoi(line);
for(int i = 0; i < indexCount; i++){
getline(fileStream, line);
vector<string> indexStr = splitString(line, " ");
GLuint i1 = stoi(indexStr[0]);
GLuint i2 = stoi(indexStr[1]);
GLuint i3 = stoi(indexStr[2]);
indices.push_back(i1);
indices.push_back(i2);
indices.push_back(i3);
}
TextureLoader textureLoader;
string texturePath = "res/models/duck/ducktex.jpg";
Texture texture = textureLoader.loadTexture(texturePath,
TextureTypes::DIFFUSE);
Texture textureSpec = textureLoader.loadTexture(texturePath,
TextureTypes::SPECULAR);
vector<Texture> textures = {texture, textureSpec};
Material material;
material.shininess = 32.0f;
Mesh mesh(vertices, indices, textures);
mesh.setMaterial(material);
vector<Mesh> meshes = {mesh};
Model model (meshes);
return model;
}