diff --git a/TODO.md b/TODO.md index 01e06b2..2dc0556 100644 --- a/TODO.md +++ b/TODO.md @@ -4,3 +4,4 @@ * Checks for errors in analyzer * Resource prep: images, fonts, font glyphs * Images if images are first they don't render correctly, just black +* Images need a cleanup process/destructor diff --git a/assets/bone.png b/assets/bone.png new file mode 100644 index 0000000..30d1791 Binary files /dev/null and b/assets/bone.png differ diff --git a/assets/test.png b/assets/test.png new file mode 100644 index 0000000..df527a2 Binary files /dev/null and b/assets/test.png differ diff --git a/assets/test_bg_small.png b/assets/test_bg_small.png new file mode 100644 index 0000000..49f1587 Binary files /dev/null and b/assets/test_bg_small.png differ diff --git a/lua/builder_test.lua b/lua/builder_test.lua index 79a1259..8016a77 100644 --- a/lua/builder_test.lua +++ b/lua/builder_test.lua @@ -9,7 +9,7 @@ config{ slide{ image{ - src="assets/test.jpg" + src="assets/test_bg_small.png" }, h1 "Image Before café", } @@ -17,7 +17,7 @@ slide{ slide{ h1 "Image After Test", image{ - src="assets/test.jpg" + src="assets/test.png" }, } diff --git a/shaders/image.vert.glsl b/shaders/image.vert.glsl index 8686529..014d28d 100644 --- a/shaders/image.vert.glsl +++ b/shaders/image.vert.glsl @@ -5,8 +5,10 @@ layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; +uniform mat4 transform; + void main() { - gl_Position = vec4(aPos, 0.0, 1.0); + gl_Position = transform * vec4(aPos, 0.0, 1.0); TexCoord = aTexCoord; } diff --git a/src/document.cpp b/src/document.cpp index c3adde7..147f62e 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1,5 +1,6 @@ #include "document.hpp" #include +#include "config.hpp" void Deck::analyze() { for(auto& slide : slides) { @@ -10,6 +11,8 @@ void Deck::analyze() { node.image = std::make_shared(); std::string src = std::any_cast(node.config.at("src")); node.image->load(src); + fmt::println("HACK! fix this"); + node.image->position = {WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2}; break; } default: diff --git a/src/engine.cpp b/src/engine.cpp index da2499e..3dc6e30 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -49,7 +49,7 @@ void init_glfw() { GLFWwindow* create_window() { - GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "LearnOpenGL", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Bezos2", NULL, NULL); dbc::check(window != NULL, "failed to open window"); glfwMakeContextCurrent(window); @@ -81,14 +81,14 @@ void setup() { void Engine::init_ui() { ui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); ui.layout( + "[=title|=*%(200,100)description|_|_|_]" "[*%(100,700)slide]" "[_]" "[_]" "[_]" "[_]" "[_]" - "[_]" - "[=title|=*%(200,100)description|_|_|_]"); + "[_]"); ui.init(); auto click = ui.entity("slide"); @@ -100,6 +100,7 @@ void Engine::init_ui() { auto title = ui.entity("title"); ui.set(title, {L"The Text Test!" }); + ui.set(title, {"assets/bone.png"}); ui.set(title, { [&](auto mods){ auto& at_title = ui.get(ui.entity("title")); diff --git a/src/guecs/opengl/components.cpp b/src/guecs/opengl/components.cpp index 886d31c..00ec6ee 100644 --- a/src/guecs/opengl/components.cpp +++ b/src/guecs/opengl/components.cpp @@ -4,14 +4,11 @@ #include #include #include +#include "config.hpp" namespace guecs { using std::make_shared; - inline SpriteTexture load_texture(const string& name, bool is_icon) { - return {}; - } - void Text::init(lel::Cell &cell, const std::string& font_file) { assert(text == nullptr && "Double init on text."); @@ -46,16 +43,18 @@ namespace guecs { void Sprite::update(const string& new_name) { if(new_name != name) { name = new_name; - // CHANGE: get the image and save it + dbc::sentinel("Swapping Images Not Implemented yet!"); } } void Sprite::init(lel::Cell &cell) { if(cell.center) stretch = false; + // handle is_icon + image = make_shared<::Image>(); + image->load(name); - auto sprite_texture = load_texture(name, is_icon); // setup the image size and such - glm::vec2 bounds{0.0, 0.0}; // get this from the image + glm::vec2 bounds{image->width, image->height}; // get this from the image if(stretch) { // handle stretch @@ -65,13 +64,23 @@ namespace guecs { float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y)); // no stretch so scale it + image->scale.x = (bounds.x / float(WINDOW_WIDTH)) * scale; + image->scale.y = (bounds.y / float(WINDOW_HEIGHT)) * scale; + + // find center point of cell since origin of image is center (for now) + image->position.x = (cell.x + box_width / 2); + image->position.y = (cell.y + box_height / 2); + + fmt::println("pos: {},{} | bounds: {},{} | box: {},{} | scale: {}", + image->position.x, image->position.y, bounds.x, bounds.y, box_width, box_height, scale); } // used the center helper here } void Sprite::render() { - + // apply position and scale.... + image->render(); } void Rectangle::init(lel::Cell& cell) { diff --git a/src/image.cpp b/src/image.cpp index deb5681..0b03262 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1,5 +1,7 @@ #include "image.hpp" #include +#include +#include "config.hpp" // these never change so just put them here float VERTICES[24] = { @@ -54,10 +56,20 @@ void Image::load(const std::string& filename) { texture_id = image_to_texture(data, width, height, nrComponents); stbi_image_free(data); + + $name = filename; } void Image::render() { shader.use(); + auto transform = glm::mat4(1.0f); + + float xpos = (2.0f * position.x) / WINDOW_WIDTH - 1.0f; + float ypos = 1.0f - (2.0f * position.y) / WINDOW_HEIGHT; + + transform = glm::translate(transform, glm::vec3(xpos, ypos, 0.0f)); + transform = glm::scale(transform, glm::vec3(scale.x, scale.y, 1.0f)); + shader.setMat4("transform", transform); // use the correct texture unit glActiveTexture(GL_TEXTURE0 + texture_unit); diff --git a/src/image.hpp b/src/image.hpp index 2fd83f5..8cb2aa4 100644 --- a/src/image.hpp +++ b/src/image.hpp @@ -4,6 +4,10 @@ struct Image { Shader shader{{"shaders/image.vert.glsl", "shaders/image.frag.glsl", ""}}; + + glm::vec2 position{0.0f, 0.0f}; + glm::vec2 scale{1.0f, 1.0f}; + unsigned int image_vao = UINT_MAX; unsigned int image_vbo = UINT_MAX; unsigned int texture_id = UINT_MAX; @@ -12,6 +16,8 @@ struct Image { int height = 0; int nrComponents = 0; // scale, rotate, position + std::string $name{"NOT SET"}; + Image(); void load(const std::string& filename);