summaryrefslogtreecommitdiff
path: root/texture.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-16 18:09:15 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-01-16 18:09:15 +0000
commit400410fcd436d5e4310bfa779f0309c5fae5b2c2 (patch)
tree89661918c487e63b6c71f2e9281b553928010606 /texture.cpp
downloadilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.tar.bz2
ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.tar.xz
ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.zip
Initial commit
Stripped back and formatted from https://github.com/BennyQBD/ModernOpenGLTutorial/
Diffstat (limited to 'texture.cpp')
-rw-r--r--texture.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/texture.cpp b/texture.cpp
new file mode 100644
index 0000000..aae16b3
--- /dev/null
+++ b/texture.cpp
@@ -0,0 +1,34 @@
+#include "texture.h"
+#include "stb_image.h"
+#include <iostream>
+
+Texture::Texture(const std::string & fileName)
+{
+ int width, height, numComponents;
+ unsigned char * data = stbi_load((fileName).c_str(), &width, &height, &numComponents, 4);
+
+ if (data == NULL)
+ std::cerr << "Unable to load texture: " << fileName << std::endl;
+
+ 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);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ stbi_image_free(data);
+}
+
+Texture::~Texture()
+{
+ glDeleteTextures(1, &m_texture);
+}
+
+void
+Texture::Bind()
+{
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+}