diff --git a/shaders/rect.frag.glsl b/shaders/rect.frag.glsl index 5131efd..9668bff 100644 --- a/shaders/rect.frag.glsl +++ b/shaders/rect.frag.glsl @@ -4,5 +4,5 @@ uniform vec4 color; void main() { - FragColor = vec4(1.0, 0.0, 0.0, 1.0); + FragColor = color; } diff --git a/src/document.cpp b/src/document.cpp index 147f62e..050e622 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -23,3 +23,7 @@ void Deck::analyze() { analyzed = true; } + +glm::vec4 Color::to_vec4() { + return {float(r) / 255.0f, float(g) / 255.0f, float(b) / 255.0f, float(a) / 255.0f}; +} diff --git a/src/document.hpp b/src/document.hpp index ddfe777..9bd68d7 100644 --- a/src/document.hpp +++ b/src/document.hpp @@ -6,6 +6,7 @@ #include #include #include "image.hpp" +#include enum class NodeType { TEXT, @@ -20,6 +21,8 @@ struct Color { uint8_t g=0; uint8_t b=0; uint8_t a=255; + + glm::vec4 to_vec4(); }; struct Node { diff --git a/src/engine.cpp b/src/engine.cpp index e4c3afe..19782d1 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -71,6 +71,7 @@ GLFWwindow* create_window() { void setup() { glEnable(GL_BLEND); glEnable(GL_CULL_FACE); + glEnable(GL_MULTISAMPLE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -99,7 +100,7 @@ void Engine::init_ui() { }); auto title = ui.entity("title"); - ui.set(title, {L"The Text Test!" }); + ui.set(title, {L"The Text Test!", 24}); ui.set(title, {"assets/bone.png"}); ui.set(title, { [&](auto mods){ @@ -110,7 +111,7 @@ void Engine::init_ui() { ui.set(title, {}); auto desc = ui.entity("description"); - ui.set(desc, {"assets/bone.png"}); + // ui.set(desc, {"assets/bone.png"}); ui.set(desc, {}); ui.init(); diff --git a/src/guecs/opengl/components.cpp b/src/guecs/opengl/components.cpp index 75dbd86..ad9ad7d 100644 --- a/src/guecs/opengl/components.cpp +++ b/src/guecs/opengl/components.cpp @@ -16,17 +16,14 @@ namespace guecs { text = make_shared<::Text>(); text->font_size = size; text->load_font(); + auto& ch = text->characters.at('H'); if(centered || cell.center) { - // WRONG! Need the scale here... - auto& ch = text->characters.at('H'); - - auto text_cell = lel::center(ch.size.x, ch.size.y, cell); - - // this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box - position = {float(text_cell.x), float(text_cell.y) - text_cell.h / 2}; + // BUG: this doesn't center, but need to render the whole text then center it + // BUG: lel::center doesn't do what I think it does + position = {float(cell.x + padding * 2), cell.mid_y + ch.size.y / 2}; } else { - position = {float(cell.x + padding * 2), float(cell.y + padding * 2)}; + position = {float(cell.x + padding * 2), float(cell.y + ch.size.y + padding * 2)}; } } @@ -55,27 +52,24 @@ namespace guecs { // setup the image size and such glm::vec2 bounds{image->width, image->height}; // get this from the image + float box_width = float(cell.w - padding * 2); + float box_height = float(cell.h - padding * 2); + + // find center point of cell since origin of image is center (for now) + // BUG: lel::center doesn't work here, why? + image->position.x = (cell.x + box_width / 2); + image->position.y = (cell.y + box_height / 2); if(stretch) { - // handle stretch - // glm::vec2 bounds{cell.w, cell.h}; // get this from the image + // handle stretch, but should use OpenGL image texture stretch options + image->scale.x = (box_width / float(WINDOW_WIDTH)); + image->scale.y = (box_height / float(WINDOW_HEIGHT)); } else { - float box_width = float(cell.w - padding * 2); - float box_height = float(cell.h - padding * 2); - float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y)); - // no stretch so scale it + float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y)); 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 } @@ -87,7 +81,10 @@ namespace guecs { void Rectangle::init(lel::Cell& cell) { shape = make_shared( float(cell.x), float(cell.y), - float(cell.w) - padding * 2.0f, float(cell.h) - padding * 2.0f); + float(cell.w) - padding * 2.0f, + float(cell.h) - padding * 2.0f, + color.to_vec4()); + shape->init(); update(); diff --git a/src/guecs/theme.hpp b/src/guecs/theme.hpp index c23829e..b4d010c 100644 --- a/src/guecs/theme.hpp +++ b/src/guecs/theme.hpp @@ -23,9 +23,9 @@ namespace guecs { int BORDER_PX = 1; unsigned int TEXT_SIZE = 30; int LABEL_SIZE = 20; - Color FILL_COLOR{255,0,0,255}; - Color TEXT_COLOR{255,0,0,255}; - Color BG_COLOR{255,0,0,255}; + Color FILL_COLOR{20,20,20,255}; + Color TEXT_COLOR{255,255,255,255}; + Color BG_COLOR{50,50,50,255}; Color BORDER_COLOR{255,0,0,255}; Color BG_COLOR_DARK{0,0,0,255}; std::string FONT_FILE_NAME{"you_forgot_to_init.otf"}; diff --git a/src/rect.cpp b/src/rect.cpp index 3e53d40..4eea9ab 100644 --- a/src/rect.cpp +++ b/src/rect.cpp @@ -6,6 +6,12 @@ #include #include "config.hpp" +void Rect::dump() { + for(size_t i = 0; i < 6; i++) { + fmt::println("{}: x={}, y={}", i, vertices[i][0], vertices[i][1]); + } +} + void Rect::init() { // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -26,6 +32,7 @@ void Rect::init() { glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0); glBindVertexArray(0); + dump(); } void Rect::render() { diff --git a/src/rect.hpp b/src/rect.hpp index 24d4106..ece6dad 100644 --- a/src/rect.hpp +++ b/src/rect.hpp @@ -10,12 +10,13 @@ struct Rect { glm::vec4 color{1.0f, 1.0f, 1.0f, 1.0f}; float vertices[6][2] = { - { x, WINDOW_HEIGHT - y + h}, - { x, WINDOW_HEIGHT - y}, - { x + w, WINDOW_HEIGHT - y}, - { x, WINDOW_HEIGHT - y + h}, - { x + w, WINDOW_HEIGHT - y}, - { x + w, WINDOW_HEIGHT - y + h} + { x, WINDOW_HEIGHT - y - h}, // left, bottom + { x + w, WINDOW_HEIGHT - y}, // right, top + { x, WINDOW_HEIGHT - y}, // left, top + + { x, WINDOW_HEIGHT - y - h}, // left, bottom + { x + w, WINDOW_HEIGHT - y - h}, // right, bottom + { x + w, WINDOW_HEIGHT - y}, // right, top }; unsigned int rect_vao = UINT_MAX; @@ -25,4 +26,5 @@ struct Rect { void init(); void render(); + void dump(); };