New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[draft]extension/window: Introduce tvg::Window based on GLFW #1690
base: main
Are you sure you want to change the base?
Conversation
tvg::Window usage if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
window = tvg::Window::gen(WIDTH, HEIGHT, "GLFW Window Example");
window->update([=](tvg::Scene* main_scene) {
auto shape1 = tvg::Shape::gen();
//...
main_scene->push(move(shape1));
auto picture = tvg::Picture::gen();
//...
main_scene->push(move(picture));
return true;
});
window->run();
window->close();
tvg::Initializer::term(tvgEngine);
} The code is not clean and tested yet. If you have any ideas, please let me know. |
Thanks. one feedback: I assume multiple canvases(windows) with different engines. So this api is more compromised? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
glTexCoord2f(0, 0); glVertex2f(0, 0);
OpenGL 1.1? I think that we should use GL2.0 at least -
static tvg::Window* instance_window;
Single window instance? We should support multiple windows with different render engines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- glTexCoord2f(0, 0); glVertex2f(0, 0);
OpenGL 1.1? I think that we should use GL2.0 at least
Thank you for feedback :) . I will update it.
- static tvg::Window* instance_window;
Single window instance? We should support multiple windows with different render engines
Actually, I didn't consider multi window.
I think we need more feature like a window manager.
How about like this?
auto window_manager = tvg::WindowManager::gen();
auto window1 = tvg::Window::gen(w, h, engine,"1", engine);
window1.update( ...);
window_manager->push(std::move(window1));
auto window2 = tvg::Window::gen(w, h, engine,"1", engine);
window2.update( ...);
window_manager->push(std::move(window2));
window_manager->run();
window_manager->close();
or
it can be changed to tvg:SingleWindow.
@SergeyLebedkin @hermet What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JSUYA I don't think window mgr concept here is necceesary...
I think this looks enough.
auto window1 = tvg::Window::gen(w, h, engine,"1", engine);
window1.run();
auto window2 = tvg::Window::gen(w, h, engine,"2", engine);
window2.run();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to manage the loop for each window, I modified it to call the static method tvg::Window::loop().
tvg::Initializer::init(tvgEngine, threads);
window = tvg::Window::gen(WIDTH, HEIGHT, "GLFW Window Example 1 (Sw)", tvg::CanvasEngine::Sw);
window->init([](tvg::Canvas* canvas) {
auto main_scene = tvg::Scene::gen();
...
canvas->push(std::move(main_scene));
return true;
});
window->update([](tvg::Canvas* canvas) {
canvas->update();
return true;
});
window2 = tvg::Window::gen(WIDTH, HEIGHT, "GLFW Window Example 2 (Gl)", tvg::CanvasEngine::Gl);
window2->init([](tvg::Canvas* canvas) {
auto main_scene = tvg::Scene::gen();
...
canvas->push(std::move(main_scene));
return true;
});
window2->update([](tvg::Canvas* canvas) {
canvas->update();
return true;
});
tvg::Window::loop();
tvg::Initializer::term(tvgEngine);
+)
I haven't updated the GL API yet.
And calling multiple GL windows doesn't work yet.
src/windows/tvgWindowImpl.h
Outdated
(void*)buffer | ||
); | ||
glBegin(GL_QUADS); | ||
glTexCoord2f(0, 0); glVertex2f(0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the texture is meant to cover the hole window, I think it's more convenient to use glBlitFramebuffer
Hi Thanks feedback. I have questions :)
|
|
960275d
to
e807100
Compare
fb53ec0
to
cff3ed4
Compare
Add an extension that uses GLFW-based tvg::Window. This window has a canvas built into it. The update() function receives a function that has tvg::Canvas as a parameter. Users can build paint into the scene. And call tvg::Window::loop(). Please refer to example/Window.cpp. [APIs] tvg::Window::gen(int width, int height, std::string name, tvg::CanvasEngine engine) void close(); void resize(int width, int height); void init(std::function<bool(tvg::Canvas*)> on_update); void update(std::function<bool(tvg::Canvas*)> on_update); static bool loop(); This idea was inspired by these: https://github.com/DeriveSDK/experiments/tree/main/glfw_imgui_tvg_window thorvg#1244 (comment)
Could you rebase to current tip? |
I know there are many members waiting for this task to progress, but I haven't been able to do it cleanly. I apologize for the delay. |
Add an extension that uses GLFW-based tvg::Window.
This window has a canvas built into it.
The update() function receives a function that has tvg::Canvas as a parameter.
Users can build paint into the scene.
And call tvg::Window::loop().
Please refer to example/Window.cpp.
[APIs]
tvg::Window::gen(int width, int height, std::string name, tvg::CanvasEngine engine)
void close();
void resize(int width, int height);
void init(std::function<bool(tvg::Canvas*)> on_update);
void update(std::function<bool(tvg::Canvas*)> on_update);
static bool loop();
This idea was inspired by these:
https://github.com/DeriveSDK/experiments/tree/main/glfw_imgui_tvg_window
#1244 (comment)