diff options
| author | Mel <einebeere@gmail.com> | 2022-10-21 01:03:18 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-21 01:03:18 +0200 |
| commit | 6ed978051668c08f5a957c97570f364dd580c807 (patch) | |
| tree | e3db93c52fcd86e26bc859d46e755290d2a7f40c /src/GFX/Texture.cpp | |
| parent | 0464a83dfaebaa75d6e2d3b7431e84ebd83fccfd (diff) | |
| download | meowcraft-6ed978051668c08f5a957c97570f364dd580c807.tar.zst meowcraft-6ed978051668c08f5a957c97570f364dd580c807.zip | |
Namespace and Folder refactor
Diffstat (limited to 'src/GFX/Texture.cpp')
| -rw-r--r-- | src/GFX/Texture.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/GFX/Texture.cpp b/src/GFX/Texture.cpp new file mode 100644 index 0000000..1942128 --- /dev/null +++ b/src/GFX/Texture.cpp @@ -0,0 +1,29 @@ +#include <GL/glew.h> +#include "Texture.hpp" + +namespace MC::GFX { + +Texture::Texture(const Image::RawImage& image) { + glGenTextures(1, &m_texture); + glBindTexture(GL_TEXTURE_2D, m_texture); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.raw()); + glGenerateMipmap(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D, 0); +} + +void Texture::bind() { + glBindTexture(GL_TEXTURE_2D, m_texture); +} + +void Texture::unbind() { + glBindTexture(GL_TEXTURE_2D, 0); +} +} \ No newline at end of file |
