diff --git a/DevScreenshots/5. UI Texture.png b/DevScreenshots/5. UI Texture.png new file mode 100644 index 0000000..9248578 Binary files /dev/null and b/DevScreenshots/5. UI Texture.png differ diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index d888445..bbabee9 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -9,7 +9,7 @@ MainState::MainState(nf::Application* app) : void MainState::onEnter() { Log("MainState onEnter!"); - } +} void MainState::update(double deltaTime) { diff --git a/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader b/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader index adb17ff..c508546 100644 --- a/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader +++ b/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader @@ -1,10 +1,10 @@ #version 330 core -out vec4 color; +in vec2 texCoord; uniform sampler2D tex; -in vec2 texCoord; +out vec4 color; void main() { color = texture(tex, texCoord); diff --git a/NFPackCreator/AssetBuild/base/shaders/textFragment.shader b/NFPackCreator/AssetBuild/base/shaders/textFragment.shader index 3a281b7..e0e208d 100644 --- a/NFPackCreator/AssetBuild/base/shaders/textFragment.shader +++ b/NFPackCreator/AssetBuild/base/shaders/textFragment.shader @@ -1,11 +1,11 @@ #version 330 core -out vec4 color; +in vec2 texCoord; uniform sampler2D text; uniform vec3 textColor; -in vec2 texCoord; +out vec4 color; void main() { vec4 temp = vec4(1.0, 1.0, 1.0, texture(text, texCoord).r); diff --git a/NFPackCreator/AssetBuild/base/shaders/textVertex.shader b/NFPackCreator/AssetBuild/base/shaders/textVertex.shader index 14988a3..96f43c2 100644 --- a/NFPackCreator/AssetBuild/base/shaders/textVertex.shader +++ b/NFPackCreator/AssetBuild/base/shaders/textVertex.shader @@ -3,7 +3,6 @@ layout(location = 0) in vec2 pos; layout(location = 1) in vec2 texCoords; -//uniform mat4 model; uniform mat4 proj; out vec2 texCoord; diff --git a/NFPackCreator/AssetBuild/base/shaders/uiTextureFragment.shader b/NFPackCreator/AssetBuild/base/shaders/uiTextureFragment.shader new file mode 100644 index 0000000..c508546 --- /dev/null +++ b/NFPackCreator/AssetBuild/base/shaders/uiTextureFragment.shader @@ -0,0 +1,11 @@ +#version 330 core + +in vec2 texCoord; + +uniform sampler2D tex; + +out vec4 color; + +void main() { + color = texture(tex, texCoord); +} diff --git a/NFPackCreator/AssetBuild/base/shaders/uiTextureVertex.shader b/NFPackCreator/AssetBuild/base/shaders/uiTextureVertex.shader new file mode 100644 index 0000000..96f43c2 --- /dev/null +++ b/NFPackCreator/AssetBuild/base/shaders/uiTextureVertex.shader @@ -0,0 +1,13 @@ +#version 330 core + +layout(location = 0) in vec2 pos; +layout(location = 1) in vec2 texCoords; + +uniform mat4 proj; + +out vec2 texCoord; + +void main() { + gl_Position = proj * vec4(pos, 0.0, 1.0); + texCoord = texCoords; +} \ No newline at end of file diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj index 4916c57..efbaefa 100644 --- a/NothinFancy/NothinFancy.vcxproj +++ b/NothinFancy/NothinFancy.vcxproj @@ -205,6 +205,7 @@ + @@ -231,6 +232,7 @@ + diff --git a/NothinFancy/NothinFancy.vcxproj.filters b/NothinFancy/NothinFancy.vcxproj.filters index 993779f..16a3c57 100644 --- a/NothinFancy/NothinFancy.vcxproj.filters +++ b/NothinFancy/NothinFancy.vcxproj.filters @@ -66,6 +66,9 @@ Source Files + + Source Files + @@ -128,6 +131,9 @@ Header Files + + Header Files + diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp index 3bf6eec..3f79555 100644 --- a/NothinFancy/src/Application.cpp +++ b/NothinFancy/src/Application.cpp @@ -121,7 +121,7 @@ namespace nf { const Config& Application::getConfig() const { return m_currentConfig; } - //TODO: Test this + int Application::getFPS() const { return m_FPS; } diff --git a/NothinFancy/src/Assets.cpp b/NothinFancy/src/Assets.cpp index f007411..3a77c9e 100644 --- a/NothinFancy/src/Assets.cpp +++ b/NothinFancy/src/Assets.cpp @@ -5,15 +5,15 @@ namespace nf { Asset::~Asset() { - + delete[] data; } AModel::~AModel() { - delete[] data; + } ATexture::~ATexture() { - delete[] data; + } AShader::~AShader() { diff --git a/NothinFancy/src/Renderer/Drawable/Entity.cpp b/NothinFancy/src/Renderer/Drawable/Entity.cpp index 11d859c..5ae09e6 100644 --- a/NothinFancy/src/Renderer/Drawable/Entity.cpp +++ b/NothinFancy/src/Renderer/Drawable/Entity.cpp @@ -30,7 +30,7 @@ namespace nf { size_t ibCount = 0; std::vector tc; parseOBJ(obj, vb, ib, ibCount, tc); - m_model->create(&vb[0], vb.size() * sizeof(float), &ib[0], ibCount, &tc[0], tc.size() * sizeof(float), texture.data, texture.size); + m_model->create(&vb[0], vb.size() * sizeof(float), &ib[0], ibCount, &tc[0], tc.size() * sizeof(float), &texture); model.alreadyLoaded = true; model.loadedModel = m_model; } @@ -52,7 +52,7 @@ namespace nf { } void Entity::setScale(double x) { - m_rotation = { x, x, x }; + m_scale = { x, x, x }; } void Entity::setScale(double x, double y, double z) { diff --git a/NothinFancy/src/Renderer/Drawable/Model.cpp b/NothinFancy/src/Renderer/Drawable/Model.cpp index 86cfff4..9049b8b 100644 --- a/NothinFancy/src/Renderer/Drawable/Model.cpp +++ b/NothinFancy/src/Renderer/Drawable/Model.cpp @@ -13,17 +13,22 @@ namespace nf { } - void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const char* textureData, size_t textureSize) { + void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, ATexture* texture) { m_vao = new VertexArray; m_vao->addBuffer(vertexBufferData, vertexBufferSize); m_vao->push(3); m_vao->finishBufferLayout(); - if (textureCoordinatesBufferData && textureCoordinatesBufferSize && textureData) { - m_vao->addBuffer(textureCoordinatesBufferData, textureCoordinatesBufferSize); - m_vao->push(2); - m_vao->finishBufferLayout(); + m_vao->addBuffer(textureCoordinatesBufferData, textureCoordinatesBufferSize); + m_vao->push(2); + m_vao->finishBufferLayout(); + if (texture->alreadyLoaded) { + m_texture = texture->loadedTexture; + } + else { m_texture = new Texture; - m_texture->create(textureData, textureSize); + m_texture->create(texture->data, texture->size); + texture->alreadyLoaded = true; + texture->loadedTexture = m_texture; } m_ib = new IndexBuffer(indexBufferData, indexBufferCount); } diff --git a/NothinFancy/src/Renderer/Drawable/Text.cpp b/NothinFancy/src/Renderer/Drawable/Text.cpp index 82305f8..70be3db 100644 --- a/NothinFancy/src/Renderer/Drawable/Text.cpp +++ b/NothinFancy/src/Renderer/Drawable/Text.cpp @@ -8,9 +8,7 @@ #include "Shader.h" namespace nf { - Text::Text() : - m_centered(false) - { + Text::Text() { } @@ -23,24 +21,32 @@ namespace nf { Error("Could not initialize FreeType!"); FT_Face face; AFont& newFont = *(AFont*)font; - if (FT_New_Memory_Face(ft, (const unsigned char*)newFont.data, newFont.size, 0, &face)) - Error("Could not load font!"); - FT_Set_Pixel_Sizes(face, 0, size); - for (unsigned char c = 0; c < 128; c++) { - FT_Load_Char(face, c, FT_LOAD_RENDER); - unsigned int tex; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, face->glyph->bitmap.width, face->glyph->bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE, face->glyph->bitmap.buffer); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - Character ch = { tex, Vec2((float)face->glyph->bitmap.width, (float)face->glyph->bitmap.rows), Vec2(face->glyph->bitmap_left, face->glyph->bitmap_top), (unsigned int)face->glyph->advance.x }; - m_font[c] = ch; + if (newFont.alreadyLoaded) { + m_font = newFont.loadedFont; + } + else { + m_font = new Font; + if (FT_New_Memory_Face(ft, (const unsigned char*)newFont.data, newFont.size, 0, &face)) + Error("Could not load font!"); + FT_Set_Pixel_Sizes(face, 0, size); + for (unsigned char c = 0; c < 128; c++) { + FT_Load_Char(face, c, FT_LOAD_RENDER); + unsigned int tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, face->glyph->bitmap.width, face->glyph->bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE, face->glyph->bitmap.buffer); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + Character ch = { tex, Vec2((float)face->glyph->bitmap.width, (float)face->glyph->bitmap.rows), Vec2(face->glyph->bitmap_left, face->glyph->bitmap_top), (unsigned int)face->glyph->advance.x }; + m_font->m_characters[c] = ch; + } + FT_Done_Face(face); + FT_Done_FreeType(ft); + newFont.alreadyLoaded = true; + newFont.loadedFont = m_font; } - FT_Done_Face(face); - FT_Done_FreeType(ft); m_vao = new VertexArray; m_vao->addBuffer(nullptr, 0); m_vao->push(2); @@ -50,8 +56,8 @@ namespace nf { m_vao->finishBufferLayout(); } - void Text::centered(bool centered) { - m_centered = centered; + void Text::setText(const std::string& string) { + m_string = string; } const char* Text::identity() { @@ -63,22 +69,24 @@ namespace nf { m_vao->bind(); std::string::const_iterator si; float currX = (float)m_position.x * windowWidth, currY = (float)m_position.y * windowHeight; - if (m_centered) { + if (m_centeredX || m_centeredY) { float textWidth = 0.0f; float textHeight = 0.0f; for (si = m_string.begin(); si != m_string.end(); si++) { - Character& c = m_font[*si]; + Character& c = m_font->m_characters[*si]; textWidth += (c.advance >> 6) * scale; if (c.size.y >= textHeight) textHeight = (float)c.size.y * scale; } - currX = ((float)windowWidth - textWidth) / 2; - currY = ((float)windowHeight - textHeight) / 2; + if (m_centeredX) + currX = ((float)windowWidth - textWidth) / 2; + if (m_centeredY) + currY = ((float)windowHeight - textHeight) / 2; } glm::vec3 color = { m_color.x, m_color.y, m_color.z }; shader->setUniform("textColor", color); for (si = m_string.begin(); si != m_string.end(); si++) { - Character& c = m_font[*si]; + Character& c = m_font->m_characters[*si]; float x = currX + (float)c.bearing.x * scale; float y = currY - float(c.size.y - c.bearing.y) * scale; float w = (float)c.size.x * scale; diff --git a/NothinFancy/src/Renderer/Drawable/UIElement.cpp b/NothinFancy/src/Renderer/Drawable/UIElement.cpp index ba5be01..6d7dbd5 100644 --- a/NothinFancy/src/Renderer/Drawable/UIElement.cpp +++ b/NothinFancy/src/Renderer/Drawable/UIElement.cpp @@ -1,7 +1,10 @@ #include "UIElement.h" namespace nf { - UIElement::UIElement() { + UIElement::UIElement() : + m_centeredX(false), + m_centeredY(false) + { } @@ -9,6 +12,18 @@ namespace nf { return "none"; } + void UIElement::setPosition(float x, float y) { + m_position = Vec2(x, y); + } + void UIElement::setPosition(const Vec2& position) { + m_position = position; + } + + void UIElement::centered(bool x, bool y) { + m_centeredX = x; + m_centeredY = y; + } + void UIElement::render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) { } diff --git a/NothinFancy/src/Renderer/Drawable/UITexture.cpp b/NothinFancy/src/Renderer/Drawable/UITexture.cpp new file mode 100644 index 0000000..f0b0112 --- /dev/null +++ b/NothinFancy/src/Renderer/Drawable/UITexture.cpp @@ -0,0 +1,76 @@ +#include "UITexture.h" + +#include "GL/glew.h" + +#include "Assets.h" +#include "Texture.h" + +namespace nf { + UITexture::UITexture() : + m_texture(0) + { + + } + + void UITexture::create(Asset* texture, const Vec2& position, double scale) { + ATexture* tex = (ATexture*)texture; + m_position = position; + m_scale = (float)scale; + if (tex->alreadyLoaded) { + m_texture = tex->loadedTexture; + } + else { + m_texture = new Texture; + m_texture->create(tex->data, tex->size); + } + + m_vao = new VertexArray; + m_vao->addBuffer(nullptr, 0); + m_vao->push(2); + m_vao->finishBufferLayout(); + m_vao->addBuffer(nullptr, 0); + m_vao->push(2); + m_vao->finishBufferLayout(); + } + + const char* UITexture::identity() { + return "texture"; + } + + void UITexture::render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) { + float posX = (float)m_position.x * windowWidth, posY = (float)m_position.y * windowHeight; + float scale = windowWidth / 5.0f; + + Vec2 texDim = m_texture->getDimensions(); + float height = scale * m_scale; + float width = ((float)texDim.x / (float)texDim.y) * scale * m_scale; + if (m_centeredX) + posX = ((float)windowWidth - width) / 2; + if (m_centeredY) + posY = ((float)windowHeight - height) / 2; + float vb[3][4] = { + posX, posY + height, + posX, posY, + posX + width, posY, + posX, posY + height, + posX + width, posY, + posX + width, posY + height + }; + float tc[3][4] = { + 0.0, 1.0, + 0.0, 0.0, + 1.0, 0.0, + 0.0, 1.0, + 1.0, 0.0, + 1.0, 1.0 + }; + m_texture->bind(); + m_vao->setBufferData(0, vb, sizeof(vb)); + m_vao->setBufferData(1, tc, sizeof(tc)); + glDrawArrays(GL_TRIANGLES, 0, 6); + } + + UITexture::~UITexture() { + + } +} \ No newline at end of file diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index d947636..94ccb19 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -49,7 +49,6 @@ namespace nf { wglMakeCurrent(m_hdc, m_hglrc); wglSwapIntervalEXT(0); Log("OpenGL version: " + std::string((char*)glGetString(GL_VERSION))); - glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -64,6 +63,9 @@ namespace nf { const char* textVertex = baseAP["textVertex.shader"]->data; const char* textFragment = baseAP["textFragment.shader"]->data; m_textShader = new Shader(textVertex, textFragment); + const char* uiTextureVertex = baseAP["uiTextureVertex.shader"]->data; + const char* uiTextureFragment = baseAP["uiTextureFragment.shader"]->data; + m_uiTextureShader = new Shader(uiTextureVertex, uiTextureFragment); BaseAssets::cube = (AModel*)baseAP["cube.obj"]; BaseAssets::plane = (AModel*)baseAP["plane.obj"]; @@ -91,6 +93,7 @@ namespace nf { glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); glm::mat4 proj = glm::perspective(glm::radians(45.0f), (float)m_app->getConfig().width / (float)m_app->getConfig().height, 0.1f, 100000.0f); for (Entity* draw : m_lGame) { Entity& curr = *draw; @@ -102,6 +105,7 @@ namespace nf { } m_lGame.clear(); + glDisable(GL_DEPTH_TEST); proj = glm::ortho(0.0f, (float)m_app->getConfig().width, 0.0f, (float)m_app->getConfig().height); for (UIElement* draw : m_lUI) { UIElement& curr = *draw; @@ -111,7 +115,11 @@ namespace nf { curr.render(m_textShader, m_app->getConfig().width, m_app->getConfig().height); continue; } - //TODO: Add else if for UI texture + if (curr.identity() == "texture") { + m_uiTextureShader->bind(); + m_uiTextureShader->setUniform("proj", proj); + curr.render(m_uiTextureShader, m_app->getConfig().width, m_app->getConfig().height); + } } m_lUI.clear(); @@ -123,6 +131,9 @@ namespace nf { } Renderer::~Renderer() { + delete m_entityShader; + delete m_textShader; + delete m_uiTextureShader; ReleaseDC(m_app->getWindow(), m_hdc); wglMakeCurrent(NULL, NULL); wglDeleteContext(m_hglrc); diff --git a/NothinFancy/src/Renderer/Texture.cpp b/NothinFancy/src/Renderer/Texture.cpp index d0a03ae..118511b 100644 --- a/NothinFancy/src/Renderer/Texture.cpp +++ b/NothinFancy/src/Renderer/Texture.cpp @@ -12,15 +12,15 @@ namespace nf { } void Texture::create(const char* textureData, size_t textureSize) { - int width, height, nChannels; + int nChannels; stbi_set_flip_vertically_on_load(true); - unsigned char* texture = stbi_load_from_memory((unsigned char*)textureData, textureSize, &width, &height, &nChannels, 0); + unsigned char* texture = stbi_load_from_memory((unsigned char*)textureData, textureSize, &m_x, &m_y, &nChannels, 0); if (!texture) Error("Texture failed to load from memory!"); glBindTexture(GL_TEXTURE_2D, m_id); 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, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_x, m_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); glGenerateMipmap(GL_TEXTURE_2D); stbi_image_free(texture); } @@ -29,6 +29,10 @@ namespace nf { glBindTexture(GL_TEXTURE_2D, m_id); } + Vec2 Texture::getDimensions() { + return { (float)m_x, (float)m_y }; + } + Texture::~Texture() { glDeleteTextures(1, &m_id); } diff --git a/NothinFancy/src/include/Assets.h b/NothinFancy/src/include/Assets.h index c6689cf..507693f 100644 --- a/NothinFancy/src/include/Assets.h +++ b/NothinFancy/src/include/Assets.h @@ -3,15 +3,17 @@ namespace nf { class Model; + class Texture; + struct Font; struct Asset { char* data; + bool alreadyLoaded = false; virtual ~Asset(); }; struct AModel : Asset { - bool alreadyLoaded; Model* loadedModel; ~AModel() override; @@ -19,6 +21,7 @@ namespace nf { struct ATexture : Asset { size_t size; + Texture* loadedTexture; ~ATexture() override; }; @@ -29,6 +32,7 @@ namespace nf { struct AFont : Asset { size_t size; + Font* loadedFont; ~AFont() override; }; diff --git a/NothinFancy/src/include/Model.h b/NothinFancy/src/include/Model.h index 14e4d44..1f4a6d8 100644 --- a/NothinFancy/src/include/Model.h +++ b/NothinFancy/src/include/Model.h @@ -1,14 +1,16 @@ #pragma once #include "Drawable.h" +#include "Assets.h" namespace nf { class Drawable; class Texture; + class Model : public Drawable { public: Model(); - void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates, size_t textureCoordinatesBufferSize, const char* textureData, size_t textureSize); + void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates, size_t textureCoordinatesBufferSize, ATexture* texture); void bind() override; ~Model(); diff --git a/NothinFancy/src/include/NothinFancy.h b/NothinFancy/src/include/NothinFancy.h index 212bb43..55684a4 100644 --- a/NothinFancy/src/include/NothinFancy.h +++ b/NothinFancy/src/include/NothinFancy.h @@ -10,6 +10,7 @@ #include "IntroGamestate.h" #include "Assets.h" #include "Text.h" +#include "UITexture.h" #include "Input.h" namespace nf { diff --git a/NothinFancy/src/include/Renderer.h b/NothinFancy/src/include/Renderer.h index cb7a40b..67d6c06 100644 --- a/NothinFancy/src/include/Renderer.h +++ b/NothinFancy/src/include/Renderer.h @@ -32,5 +32,6 @@ namespace nf { std::vector m_lUI; Shader* m_entityShader; Shader* m_textShader; + Shader* m_uiTextureShader; }; } \ No newline at end of file diff --git a/NothinFancy/src/include/Text.h b/NothinFancy/src/include/Text.h index f1eec91..264f532 100644 --- a/NothinFancy/src/include/Text.h +++ b/NothinFancy/src/include/Text.h @@ -13,22 +13,23 @@ namespace nf { unsigned int advance; }; + struct Font { + std::map m_characters; + }; + class Text : public UIElement { public: Text(); void create(const std::string& string, const Vec2& position, const Vec3& color = {1.0, 1.0, 1.0}, unsigned int size = 160, Asset* font = BaseAssets::defaultFont); - void centered(bool centered); - + void setText(const std::string& string); const char* identity() override; void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) override; ~Text(); private: std::string m_string; - Vec2 m_position; + Font* m_font; Vec3 m_color; - bool m_centered; - std::map m_font; }; } \ No newline at end of file diff --git a/NothinFancy/src/include/Texture.h b/NothinFancy/src/include/Texture.h index 3b31cb5..c917fc7 100644 --- a/NothinFancy/src/include/Texture.h +++ b/NothinFancy/src/include/Texture.h @@ -1,4 +1,5 @@ #pragma once +#include "Utility.h" namespace nf { class Texture { @@ -7,9 +8,12 @@ namespace nf { void create(const char* textureData, size_t textureSize); void bind(); + Vec2 getDimensions(); ~Texture(); private: unsigned int m_id; + int m_x; + int m_y; }; } \ No newline at end of file diff --git a/NothinFancy/src/include/UIElement.h b/NothinFancy/src/include/UIElement.h index 84664a2..a862b52 100644 --- a/NothinFancy/src/include/UIElement.h +++ b/NothinFancy/src/include/UIElement.h @@ -1,6 +1,8 @@ #pragma once #include "Drawable.h" +#include "Utility.h" + namespace nf { class Shader; @@ -9,10 +11,15 @@ namespace nf { UIElement(); virtual const char* identity(); + void setPosition(float x, float y); + void setPosition(const Vec2& position); + void centered(bool x, bool y = false); virtual void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight); ~UIElement(); - private: - + protected: + Vec2 m_position; + bool m_centeredX; + bool m_centeredY; }; } \ No newline at end of file diff --git a/NothinFancy/src/include/UITexture.h b/NothinFancy/src/include/UITexture.h new file mode 100644 index 0000000..2e34ac1 --- /dev/null +++ b/NothinFancy/src/include/UITexture.h @@ -0,0 +1,22 @@ +#pragma once +#include "UIElement.h" +#include "Utility.h" + +namespace nf { + class Texture; + struct Asset; + + class UITexture : public UIElement { + public: + UITexture(); + + void create(Asset* texture, const Vec2& position, double scale = 1.0); + const char* identity() override; + void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) override; + + ~UITexture(); + private: + Texture* m_texture; + float m_scale; + }; +} \ No newline at end of file