diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-12-22 12:16:38 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-12-22 12:16:38 +0000 |
commit | e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3 (patch) | |
tree | 1612baf22456c0b5a1bef82980177afb34b2756c /ui/icon.cpp | |
parent | Window handles UIComponent rendering (diff) | |
download | ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.tar.bz2 ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.tar.xz ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.zip |
Initial commit with some basic UI
Diffstat (limited to 'ui/icon.cpp')
-rw-r--r-- | ui/icon.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ui/icon.cpp b/ui/icon.cpp new file mode 100644 index 0000000..371410a --- /dev/null +++ b/ui/icon.cpp @@ -0,0 +1,33 @@ +#include "icon.h"
+#include <gfx/image.h>
+#include <resource.h>
+#include <stb/stb_image.h>
+
+Icon::Icon(const std::filesystem::path & fileName) : Icon {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}}
+{
+}
+
+Icon::Icon(const Image & tex) : size {tex.width, tex.height}, m_texture {}
+{
+ glGenTextures(1, &m_texture);
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
+}
+
+Icon::~Icon()
+{
+ glDeleteTextures(1, &m_texture);
+}
+
+void
+Icon::Bind() const
+{
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+}
|