From 7b73c6f742994b2bbbaa4db508654d1fc4595f1b Mon Sep 17 00:00:00 2001 From: Byte-Wh1te Date: Sun, 14 Jan 2024 13:49:10 +0200 Subject: [PATCH] Texture fix --- include/Calamity/Texture.h | 2 ++ src/Texture.cpp | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/Calamity/Texture.h b/include/Calamity/Texture.h index c20ea5d..e80428b 100644 --- a/include/Calamity/Texture.h +++ b/include/Calamity/Texture.h @@ -20,10 +20,12 @@ namespace clm std::string m_FilePath; int m_Width, m_Height, m_BPP; public: + Texture(); Texture(const std::string& path,TextureFormat format = TextureFormat::None); Texture(int width, int height,TextureFormat format, const void* data = nullptr); void SetData(void* data); void Resize(int width,int height); + void LoadImage(const std::string& path,TextureFormat format = TextureFormat::None); ~Texture(); void Bind(unsigned int slot = 0) const; diff --git a/src/Texture.cpp b/src/Texture.cpp index ac5a9d6..3215325 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -5,20 +5,30 @@ namespace clm { + Texture::Texture() + { + glGenTextures(1, &m_RendererID); + } + Texture::Texture(const std::string& path,TextureFormat format) : m_RendererID(0), m_FilePath(path), m_Width(0), m_Height(0), m_BPP(0) { - unsigned char* m_LocalBuffer = nullptr; + glGenTextures(1, &m_RendererID); + LoadImage(path); + } + + void Texture::LoadImage(const std::string& path,TextureFormat format) + { + glBindTexture(GL_TEXTURE_2D, m_RendererID); stbi_set_flip_vertically_on_load(1); + unsigned char* m_LocalBuffer = nullptr; m_LocalBuffer = stbi_load(path.c_str(), &m_Width, &m_Height, &m_BPP, 0); if (!m_LocalBuffer) { std::cout<<"Can't load texture '"<