canvas pan/zoom, project into canvas using inverse transform, implement eraser (early prototype)
This commit is contained in:
@@ -195,6 +195,22 @@ void App::initShaders()
|
||||
" mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);\n"
|
||||
" frag = vec4(rgb, alpha_tot);\n"
|
||||
"}\n";
|
||||
// ERASER
|
||||
static const char* shader_stroke_erase_f =
|
||||
SHADER_VERSION
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
"uniform mediump vec4 col;\n"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
"out mediump vec4 frag;\n"
|
||||
"void main(){\n"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float brush_alpha = ( 1.0 - texture(tex, uv).r ) * alpha;\n"
|
||||
" mediump vec4 bg = texture(tex_bg, uv2);\n"
|
||||
" frag = vec4(bg.rgb, bg.a - bg.a * brush_alpha);\n"
|
||||
"}\n";
|
||||
|
||||
// STROKE LAYER BLEND
|
||||
static const char* shader_stroke_layer_v =
|
||||
@@ -243,6 +259,8 @@ void App::initShaders()
|
||||
LOG("Failed to create shader Atlas");
|
||||
if (!ShaderManager::create(kShader::Stroke, shader_stroke_v, shader_stroke_f))
|
||||
LOG("Failed to create shader Stroke");
|
||||
if (!ShaderManager::create(kShader::StrokeErase, shader_stroke_v, shader_stroke_erase_f))
|
||||
LOG("Failed to create shader StrokeErase");
|
||||
if (!ShaderManager::create(kShader::StrokeLayer, shader_stroke_layer_v, shader_stroke_layer_f))
|
||||
LOG("Failed to create shader StrokeLayer");
|
||||
LOG("shaders initialized");
|
||||
@@ -311,7 +329,11 @@ void App::initLayout()
|
||||
stroke->loaded();
|
||||
|
||||
if (canvas)
|
||||
{
|
||||
stroke->m_canvas->m_brush.m_tip_color = color->m_color;
|
||||
stroke->m_canvas->draw_stroke();
|
||||
canvas->m_brush = stroke->m_canvas->m_brush;
|
||||
}
|
||||
|
||||
brushes->on_brush_changed = [this](Node* target, int index) {
|
||||
auto tid = brushes->get_texture_id(index);
|
||||
@@ -324,7 +346,7 @@ void App::initLayout()
|
||||
|
||||
color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
stroke->m_canvas->m_brush.m_tip_color = color;
|
||||
stroke->m_canvas->draw_stroke();
|
||||
// stroke->m_canvas->draw_stroke();
|
||||
if (canvas)
|
||||
canvas->m_brush = stroke->m_canvas->m_brush;
|
||||
if (on_color_change)
|
||||
@@ -359,61 +381,25 @@ void App::initLayout()
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != stroke.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(stroke));
|
||||
current_panel = stroke.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
panels->get_child_index(stroke.get()) == -1 ? panels->add_child(stroke) : panels->remove_child(stroke.get());
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != brushes.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(brushes));
|
||||
current_panel = brushes.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
panels->get_child_index(brushes.get()) == -1 ? panels->add_child(brushes) : panels->remove_child(brushes.get());
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-color"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != color.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(color));
|
||||
current_panel = color.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
panels->get_child_index(color.get()) == -1 ? panels->add_child(color) : panels->remove_child(color.get());
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-layer"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != layers.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(layers));
|
||||
current_panel = layers.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
panels->get_child_index(layers.get()) == -1 ? panels->add_child(layers) : panels->remove_child(layers.get());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -428,13 +414,14 @@ void App::initLayout()
|
||||
button->m_text->set_text(canvas->m_canvas->m_use_instanced ? "INST" : "NORM");
|
||||
}
|
||||
};
|
||||
button->m_text->set_text("NORM");
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-close"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
//exit(0);
|
||||
if (canvas)
|
||||
canvas->m_canvas->clear();
|
||||
canvas->m_canvas->clear({ 0, 0, 0, 0 });
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-popup"))
|
||||
@@ -536,7 +523,7 @@ void App::init()
|
||||
LOG("OPENGL: %.*s", length, message);
|
||||
FlushConsoleInputBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), info.wAttributes);
|
||||
__debugbreak();
|
||||
//__debugbreak();
|
||||
}
|
||||
}, nullptr);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
|
||||
Reference in New Issue
Block a user