Skip to content

Commit

Permalink
Add texture wrap options to texture loader
Browse files Browse the repository at this point in the history
  • Loading branch information
cjhoward committed Jul 11, 2017
1 parent 91e6526 commit 0de6664
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
13 changes: 13 additions & 0 deletions include/emergent/graphics/texture-loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ class TextureLoader
*/
void setMaxAnisotropy(float anisotropy);

/// Enables or disables repeating the texture S coordinates
void setWrapS(bool repeat);

/// Enables or disables repeating the texture T coordinates
void setWrapT(bool repeat);

/// Enables or disables repeating the texture R coordinates
void setWrapR(bool repeat);

private:
enum class CubemapLayout
{
Expand All @@ -99,6 +108,10 @@ class TextureLoader
bool mipmapChain;
bool cubemap;
float maxAnisotropy;

bool wrapRepeatS;
bool wrapRepeatT;
bool wrapRepeatR;
};

} // namespace Emergent
Expand Down
4 changes: 4 additions & 0 deletions src/emergent/graphics/billboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ void BillboardBatch::update()
alignment = glm::normalize(lookRotation(look, up));
}
}
else
{
alignment = billboard.getRotation();
}

Vector2 offset = dimensions * 0.5f;
Vector3 v0 = translation + alignment * Vector3(-offset.x, -offset.y, 0.0f);
Expand Down
30 changes: 24 additions & 6 deletions src/emergent/graphics/texture-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ TextureLoader::TextureLoader():
gamma(1.0f),
mipmapChain(false),
cubemap(false),
maxAnisotropy(1.0f)
maxAnisotropy(1.0f),
wrapRepeatS(true),
wrapRepeatT(true),
wrapRepeatR(true)
{}

Texture* TextureLoader::load(const std::string& filename)
Expand All @@ -169,8 +172,8 @@ Texture* TextureLoader::load(const std::string& filename)
glBindTexture(GL_TEXTURE_2D, textureID);

// Set wrapping and filtering parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (wrapRepeatS) ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (wrapRepeatT) ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Expand Down Expand Up @@ -227,6 +230,21 @@ void TextureLoader::setMaxAnisotropy(float anisotropy)
this->maxAnisotropy = anisotropy;
}

void TextureLoader::setWrapS(bool repeat)
{
this->wrapRepeatS = repeat;
}

void TextureLoader::setWrapT(bool repeat)
{
this->wrapRepeatT = repeat;
}

void TextureLoader::setWrapR(bool repeat)
{
this->wrapRepeatR = repeat;
}

Texture* TextureLoader::loadCubemap(const std::string& filename)
{
// Generate OpenGL texture ID
Expand All @@ -235,9 +253,9 @@ Texture* TextureLoader::loadCubemap(const std::string& filename)
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);

// Set wrapping and filtering parameters
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, (wrapRepeatS) ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, (wrapRepeatT) ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, (wrapRepeatR) ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Expand Down

0 comments on commit 0de6664

Please sign in to comment.