summary refs log tree commit diff
path: root/src/Texture.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-10 16:23:26 +0200
committerMel <einebeere@gmail.com>2022-10-10 16:23:26 +0200
commitcb3ddae385c03a8830d39dc37fcd5bf273524d5e (patch)
tree0ccddcd6b32838b8fc2b65805a4fba96c4c0ff39 /src/Texture.cpp
parent799c06e0387e01bdb8a10019be6192f9db00a824 (diff)
downloadmeowcraft-cb3ddae385c03a8830d39dc37fcd5bf273524d5e.tar.zst
meowcraft-cb3ddae385c03a8830d39dc37fcd5bf273524d5e.zip
Try to add second VBO
Diffstat (limited to 'src/Texture.cpp')
-rw-r--r--src/Texture.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Texture.cpp b/src/Texture.cpp
new file mode 100644
index 0000000..d32a75a
--- /dev/null
+++ b/src/Texture.cpp
@@ -0,0 +1,27 @@
+#include <GL/glew.h>
+#include "Texture.hpp"
+
+namespace MC {
+
+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);
+}
+
+void Texture::bind() {
+    glBindTexture(GL_TEXTURE_2D, m_texture);
+}
+
+void Texture::unbind() {
+    glBindTexture(GL_TEXTURE_2D, 0);
+}
+}
\ No newline at end of file