diff --git a/include/uui/config.hpp b/include/uui/config.hpp new file mode 100644 index 0000000..1afb3a0 --- /dev/null +++ b/include/uui/config.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "graphic_context.hpp" + +namespace Config +{ +constexpr unsigned int FONT_TEXTURE_UNIT = GL_TEXTURE0; +} diff --git a/include/uui/opengl/component.hpp b/include/uui/opengl/component.hpp index 1f44a39..b2c57bc 100644 --- a/include/uui/opengl/component.hpp +++ b/include/uui/opengl/component.hpp @@ -18,7 +18,7 @@ public: GlComponent(GlComponent&&) = delete; ~GlComponent(); - void set_background_color(float r, float g, float b, float a = 0.0f); + void set_background_color(float r, float g, float b, float a = 1.0f); protected: std::shared_ptr window; diff --git a/manifest.md b/manifest.md new file mode 100644 index 0000000..b7f40bd --- /dev/null +++ b/manifest.md @@ -0,0 +1,30 @@ +# UUI : micro UI Toolkit + + +* C++ + Vulkan/OpenGL + +* Python binding + +* Ease of use : safe and good semantic + +* Let custom rendering + + +## Technical + +* minimum ressource : CPU/memory + +* minimum redraw + +* core profile : no immediate mode + +* Object based + +* Init/Render lambda + +* Opengl context + + +## Layout / Style + +* Constraint based? padding/margin? diff --git a/src/test/example_gl.cpp b/src/test/example_gl.cpp index 8f82bb9..f1eeb8b 100644 --- a/src/test/example_gl.cpp +++ b/src/test/example_gl.cpp @@ -15,10 +15,12 @@ int main() uui::GlApplication app; // uui::GlApplication app2; // exception : application already created auto window = app.create_window(800, 600, "OpenGl!"); - // auto comp = window->create_component(0, 100, 0.5f, 50); - // comp->set_background_color(0.8f, 0.1f, 0.5f); + auto comp = window->create_component(0, 100, 0.5f, 50); + comp->set_background_color(0.8f, 0.1f, 0.5f); + comp = window->create_component(0.25f, 50, 0.4f, 150); + comp->set_background_color(0.3f, 0.8f, 0.4f, 0.5f); auto label = window->create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f}); - label->set_background_color(0.1f, 0.2f, 0.5f); + label->set_background_color(0.1f, 0.2f, 0.5f, 0.8f); label = window->create_label(0.5f, 0.5f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f}); label->set_background_color(0.5f, 0.5f, 0.1f); label = window->create_label(0.75f, 0.75f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.1f}); @@ -32,9 +34,12 @@ int main() // comp->set_background_color(0.8f, 0.1f, 0.5f); // comp = window_1->create_component(0.75f, 0.75f, 0.25f, 0.25f); // comp->set_background_color(0.2f, 0.1f, 0.5f); + // auto window_2 = app.create_window(600, 600, "OpenGL 2!"); // comp = window_2->create_component(0, 0.5f, 100, 0.5f); // comp->set_background_color(0.2f, 0.5f, 0.3f); + // auto label = window_2->create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f}); + // label->set_background_color(0.1f, 0.2f, 0.5f); // app.run(); // } } diff --git a/src/uui/opengl/component.cpp b/src/uui/opengl/component.cpp index 922c016..1a43e76 100644 --- a/src/uui/opengl/component.cpp +++ b/src/uui/opengl/component.cpp @@ -40,7 +40,7 @@ uui::GlComponent::~GlComponent() deinit(); } -void uui::GlComponent::set_background_color(float r, float g, float b, float a) +void uui::GlComponent::set_background_color(float r, float g, float b, float a /*=0.0f*/) { background_color = {r, g, b, a}; glBindVertexArray(gl_vao); @@ -95,12 +95,14 @@ void uui::GlComponent::set_vbo_data() float x_max = x_min + (2.0f * vert_w); float y_min = (-2.0f * vert_y) + 1.0f; float y_max = y_min - (2.0f * vert_h); + std::cout << "Sending vbo data with color: " << background_color[0] << ", " << background_color[1] << ", " << background_color[2] << ", " + << background_color[3] << std::endl; // clang-format off float vertices[] = { - x_max, y_min, 0.0f, background_color[0] , background_color[1], background_color[2], background_color[3], // top right - x_max, y_max, 0.0f, background_color[0] , background_color[1], background_color[2], background_color[3], // bottom right - x_min, y_max, 0.0f, background_color[0] , background_color[1], background_color[2], background_color[3], // bottom left - x_min, y_min, 0.0f, background_color[0] , background_color[1], background_color[2], background_color[3] // top left + x_max, y_min, background_color[0] , background_color[1], background_color[2], background_color[3], // top right + x_max, y_max, background_color[0] , background_color[1], background_color[2], background_color[3], // bottom right + x_min, y_max, background_color[0] , background_color[1], background_color[2], background_color[3], // bottom left + x_min, y_min, background_color[0] , background_color[1], background_color[2], background_color[3] // top left }; // clang-format on glBindBuffer(GL_ARRAY_BUFFER, gl_vbo); @@ -108,20 +110,20 @@ void uui::GlComponent::set_vbo_data() glVertexAttribPointer( 0, // index - 3, // size + 2, // size GL_FLOAT, // type GL_FALSE, // enable normalization, - 7 * sizeof(float), // stride + 6 * sizeof(float), // stride (void*)0 // offset ); glEnableVertexAttribArray(0); glVertexAttribPointer( 1, // index - 3, // size + 4, // size GL_FLOAT, // type GL_FALSE, // enable normalization, - 7 * sizeof(float), // stride - (void*)(3 * sizeof(float)) // offset + 6 * sizeof(float), // stride + (void*)(2 * sizeof(float)) // offset ); glEnableVertexAttribArray(1); } diff --git a/src/uui/opengl/font_manager.cpp b/src/uui/opengl/font_manager.cpp index ec1b478..546ae6e 100644 --- a/src/uui/opengl/font_manager.cpp +++ b/src/uui/opengl/font_manager.cpp @@ -6,6 +6,7 @@ #include #include +#include "uui/config.hpp" #include "uui/opengl/application.hpp" #include "uui/opengl/gl_utils.hpp" #include "uui/shader.hpp" @@ -166,7 +167,7 @@ const uui::GlFontManager::Font& uui::GlFontManager::init_font(const std::string& glLinkProgram(gl_program); // Create a texture that will be used to hold all ASCII glyphs - glActiveTexture(GL_TEXTURE0); + glActiveTexture(Config::FONT_TEXTURE_UNIT); glGenTextures(1, &font.atlas_texture); glBindTexture(GL_TEXTURE_2D, font.atlas_texture); @@ -249,7 +250,7 @@ void uui::GlFontManager::render_text( glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)(&gl_prev_program)); glUseProgram(gl_program); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(Config::FONT_TEXTURE_UNIT); auto [color_r, color_g, color_b, color_a] = text_color; glUniform4f(glGetUniformLocation(gl_program, "textColor"), color_r, color_g, color_b, color_a); glBindVertexArray(gl_vao); diff --git a/src/uui/opengl/shaders/main.frag b/src/uui/opengl/shaders/main.frag index 58aeffd..7dca716 100644 --- a/src/uui/opengl/shaders/main.frag +++ b/src/uui/opengl/shaders/main.frag @@ -7,4 +7,5 @@ in vec4 backgroundColor; void main() { FragColor = backgroundColor; + // FragColor = vec4(backgroundColor.xyz * backgroundColor.a, backgroundColor.a); // premultiply } diff --git a/src/uui/opengl/window.cpp b/src/uui/opengl/window.cpp index eb4618c..d728d77 100644 --- a/src/uui/opengl/window.cpp +++ b/src/uui/opengl/window.cpp @@ -120,7 +120,8 @@ void uui::GlWindow::init() // glEnable(GL_CULL_FACE); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); if constexpr(uui::GlApplication::debug_mode) {