Fix color blending (component VAO), add config.hpp
This commit is contained in:
parent
1a200205a5
commit
b530f65f38
8 changed files with 65 additions and 17 deletions
8
include/uui/config.hpp
Normal file
8
include/uui/config.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "graphic_context.hpp"
|
||||||
|
|
||||||
|
namespace Config
|
||||||
|
{
|
||||||
|
constexpr unsigned int FONT_TEXTURE_UNIT = GL_TEXTURE0;
|
||||||
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ public:
|
||||||
GlComponent(GlComponent&&) = delete;
|
GlComponent(GlComponent&&) = delete;
|
||||||
~GlComponent();
|
~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:
|
protected:
|
||||||
std::shared_ptr<GlWindow> window;
|
std::shared_ptr<GlWindow> window;
|
||||||
|
|
|
||||||
30
manifest.md
Normal file
30
manifest.md
Normal file
|
|
@ -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?
|
||||||
|
|
@ -15,10 +15,12 @@ int main()
|
||||||
uui::GlApplication app;
|
uui::GlApplication app;
|
||||||
// uui::GlApplication app2; // exception : application already created
|
// uui::GlApplication app2; // exception : application already created
|
||||||
auto window = app.create_window(800, 600, "OpenGl!");
|
auto window = app.create_window(800, 600, "OpenGl!");
|
||||||
// auto comp = window->create_component(0, 100, 0.5f, 50);
|
auto comp = window->create_component(0, 100, 0.5f, 50);
|
||||||
// comp->set_background_color(0.8f, 0.1f, 0.5f);
|
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});
|
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 = 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->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});
|
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->set_background_color(0.8f, 0.1f, 0.5f);
|
||||||
// comp = window_1->create_component(0.75f, 0.75f, 0.25f, 0.25f);
|
// comp = window_1->create_component(0.75f, 0.75f, 0.25f, 0.25f);
|
||||||
// comp->set_background_color(0.2f, 0.1f, 0.5f);
|
// comp->set_background_color(0.2f, 0.1f, 0.5f);
|
||||||
|
|
||||||
// auto window_2 = app.create_window(600, 600, "OpenGL 2!");
|
// auto window_2 = app.create_window(600, 600, "OpenGL 2!");
|
||||||
// comp = window_2->create_component(0, 0.5f, 100, 0.5f);
|
// comp = window_2->create_component(0, 0.5f, 100, 0.5f);
|
||||||
// comp->set_background_color(0.2f, 0.5f, 0.3f);
|
// 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();
|
// app.run();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ uui::GlComponent::~GlComponent()
|
||||||
deinit();
|
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};
|
background_color = {r, g, b, a};
|
||||||
glBindVertexArray(gl_vao);
|
glBindVertexArray(gl_vao);
|
||||||
|
|
@ -95,12 +95,14 @@ void uui::GlComponent::set_vbo_data()
|
||||||
float x_max = x_min + (2.0f * vert_w);
|
float x_max = x_min + (2.0f * vert_w);
|
||||||
float y_min = (-2.0f * vert_y) + 1.0f;
|
float y_min = (-2.0f * vert_y) + 1.0f;
|
||||||
float y_max = y_min - (2.0f * vert_h);
|
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
|
// clang-format off
|
||||||
float vertices[] = {
|
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_min, 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_max, y_max, 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_max, 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_min, y_min, background_color[0] , background_color[1], background_color[2], background_color[3] // top left
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, gl_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, gl_vbo);
|
||||||
|
|
@ -108,20 +110,20 @@ void uui::GlComponent::set_vbo_data()
|
||||||
|
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
0, // index
|
0, // index
|
||||||
3, // size
|
2, // size
|
||||||
GL_FLOAT, // type
|
GL_FLOAT, // type
|
||||||
GL_FALSE, // enable normalization,
|
GL_FALSE, // enable normalization,
|
||||||
7 * sizeof(float), // stride
|
6 * sizeof(float), // stride
|
||||||
(void*)0 // offset
|
(void*)0 // offset
|
||||||
);
|
);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
1, // index
|
1, // index
|
||||||
3, // size
|
4, // size
|
||||||
GL_FLOAT, // type
|
GL_FLOAT, // type
|
||||||
GL_FALSE, // enable normalization,
|
GL_FALSE, // enable normalization,
|
||||||
7 * sizeof(float), // stride
|
6 * sizeof(float), // stride
|
||||||
(void*)(3 * sizeof(float)) // offset
|
(void*)(2 * sizeof(float)) // offset
|
||||||
);
|
);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "uui/config.hpp"
|
||||||
#include "uui/opengl/application.hpp"
|
#include "uui/opengl/application.hpp"
|
||||||
#include "uui/opengl/gl_utils.hpp"
|
#include "uui/opengl/gl_utils.hpp"
|
||||||
#include "uui/shader.hpp"
|
#include "uui/shader.hpp"
|
||||||
|
|
@ -166,7 +167,7 @@ const uui::GlFontManager::Font& uui::GlFontManager::init_font(const std::string&
|
||||||
glLinkProgram(gl_program);
|
glLinkProgram(gl_program);
|
||||||
|
|
||||||
// Create a texture that will be used to hold all ASCII glyphs
|
// 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);
|
glGenTextures(1, &font.atlas_texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, 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));
|
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)(&gl_prev_program));
|
||||||
glUseProgram(gl_program);
|
glUseProgram(gl_program);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(Config::FONT_TEXTURE_UNIT);
|
||||||
auto [color_r, color_g, color_b, color_a] = text_color;
|
auto [color_r, color_g, color_b, color_a] = text_color;
|
||||||
glUniform4f(glGetUniformLocation(gl_program, "textColor"), color_r, color_g, color_b, color_a);
|
glUniform4f(glGetUniformLocation(gl_program, "textColor"), color_r, color_g, color_b, color_a);
|
||||||
glBindVertexArray(gl_vao);
|
glBindVertexArray(gl_vao);
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,5 @@ in vec4 backgroundColor;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = backgroundColor;
|
FragColor = backgroundColor;
|
||||||
|
// FragColor = vec4(backgroundColor.xyz * backgroundColor.a, backgroundColor.a); // premultiply
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,8 @@ void uui::GlWindow::init()
|
||||||
|
|
||||||
// glEnable(GL_CULL_FACE);
|
// glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
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)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue