diff --git a/examples/render/00-hello-triangle/bgfx/CMakeLists.txt b/examples/render/00-hello-triangle/bgfx/CMakeLists.txt index 04f06cfc4..b7584a946 100644 --- a/examples/render/00-hello-triangle/bgfx/CMakeLists.txt +++ b/examples/render/00-hello-triangle/bgfx/CMakeLists.txt @@ -22,9 +22,9 @@ cmake_minimum_required(VERSION 3.24) -if (TARGET vclib-3rd-qt) - add_subdirectory(qt) -endif() if (TARGET vclib-3rd-glfw) add_subdirectory(glfw) endif() +if (TARGET vclib-3rd-qt) + add_subdirectory(qt) +endif() diff --git a/examples/render/04-hello-triangle-imgui/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/CMakeLists.txt new file mode 100644 index 000000000..d451482de --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/CMakeLists.txt @@ -0,0 +1,31 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +if (TARGET vclib-3rd-imgui) + if (VCLIB_RENDER_BACKEND STREQUAL "bgfx") + add_subdirectory(bgfx) + elseif (VCLIB_RENDER_BACKEND STREQUAL "opengl2") + add_subdirectory(opengl2) + endif() +endif() diff --git a/examples/render/04-hello-triangle-imgui/bgfx/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/bgfx/CMakeLists.txt new file mode 100644 index 000000000..e9a8dd681 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/CMakeLists.txt @@ -0,0 +1,30 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +if (TARGET vclib-3rd-glfw) + add_subdirectory(glfw) +endif() +if (TARGET vclib-3rd-qt) + #add_subdirectory(qt) +endif() diff --git a/examples/render/04-hello-triangle-imgui/bgfx/common.h b/examples/render/04-hello-triangle-imgui/bgfx/common.h new file mode 100644 index 000000000..767f1a9d8 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/common.h @@ -0,0 +1,83 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef COMMON_H +#define COMMON_H + +#include + +#include +#include + +struct Vertex +{ + float pos[2]; + uint32_t abgr; +}; + +static const Vertex vertices[] { + {{-1.0f, -1.0f}, vcl::Color(vcl::Color::Red).abgr() }, + {{1.0f, -1.0f}, vcl::Color(vcl::Color::Green).abgr()}, + {{0.0f, 1.0f}, vcl::Color(vcl::Color::Blue).abgr() }, +}; + +inline void setUpBGFX( + bgfx::ViewId viewId, + bgfx::VertexBufferHandle& vbh, + bgfx::ProgramHandle& program) +{ + vcl::Color backgroundColor = vcl::Color::Black; + + bgfx::setViewClear( + viewId, + BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, + backgroundColor.rgba(), + 1.0f, + 0); + + bgfx::VertexLayout layout; + + layout.begin() + .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) + .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true) + .end(); + + vbh = bgfx::createVertexBuffer( + bgfx::makeRef(vertices, sizeof(vertices)), layout); + + program = vcl::loadProgram( + "shaders/vs_vertex_shader", "shaders/fs_fragment_shader"); + + bgfx::touch(viewId); +} + +inline void drawOnView( + bgfx::ViewId viewId, + const bgfx::VertexBufferHandle& vbh, + const bgfx::ProgramHandle& program) +{ + bgfx::setVertexBuffer(0, vbh); + + bgfx::submit(viewId, program); +} + +#endif // COMMON_H diff --git a/examples/render/04-hello-triangle-imgui/bgfx/glfw/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/bgfx/glfw/CMakeLists.txt new file mode 100644 index 000000000..455a3de40 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/glfw/CMakeLists.txt @@ -0,0 +1,48 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +set(EXAMPLE_NAME 04-hello-triangle-imgui-glfw) +project(vclib-render-example-${EXAMPLE_NAME}) + +### Build settings +set(CMAKE_CXX_STANDARD 20) + +set(HEADERS + ../common.h + ../hello_triangle_drawer.h + ../../demo_imgui_drawer.h) + +set(SOURCES + main.cpp) + +set(SHADERS + shaders/vs_vertex_shader.sc + shaders/fs_fragment_shader.sc + shaders/varying.def.sc) + +vclib_add_example(${EXAMPLE_NAME} + VCLIB_MODULE render + SOURCES ${HEADERS} ${SOURCES}) + +target_add_bgfx_shaders(${PROJECT_NAME} ${SHADERS}) diff --git a/examples/render/04-hello-triangle-imgui/bgfx/glfw/main.cpp b/examples/render/04-hello-triangle-imgui/bgfx/glfw/main.cpp new file mode 100644 index 000000000..543195a0f --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/glfw/main.cpp @@ -0,0 +1,51 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#include "../../demo_imgui_drawer.h" +#include "../hello_triangle_drawer.h" + +#include +#include +#include + +/** + * This Demo is a simple example of how to use the ImGuiDrawer to draw the ImGui + * demo window. + * + * The example is the same as 00-hello-triangle, but with the addition of the + * ImGui demo window. + */ +int main(int argc, char** argv) +{ + // The window is created with the RenderApp class: + using WindowGLFW = vcl::RenderApp< + vcl::glfw::WindowManager, // The WindowManager: GLFW + vcl::Canvas, // The default Canvas + DemoImGuiDrawer, // A Drawer that draws the ImGui demo window + HelloTriangleDrawer>; // The Drawer that draws the triangle + + WindowGLFW tw("Hello Triangle ImGui with GLFW"); + + tw.show(); + + return 0; +} diff --git a/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/fs_fragment_shader.sc b/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/fs_fragment_shader.sc new file mode 100644 index 000000000..fd4cbb186 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/fs_fragment_shader.sc @@ -0,0 +1,8 @@ +$input v_color + +#include + +void main() +{ + gl_FragColor = v_color; +} diff --git a/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/varying.def.sc b/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/varying.def.sc new file mode 100644 index 000000000..ec1306b83 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/varying.def.sc @@ -0,0 +1,4 @@ +vec2 a_position : POSITION; +vec4 a_color0 : COLOR0; + +vec4 v_color : COLOR0; diff --git a/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/vs_vertex_shader.sc b/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/vs_vertex_shader.sc new file mode 100644 index 000000000..581eaeb7d --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/glfw/shaders/vs_vertex_shader.sc @@ -0,0 +1,12 @@ +$input a_position +$input a_color0 + +$output v_color + +#include + +void main() +{ + gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); + v_color = a_color0; +} diff --git a/examples/render/04-hello-triangle-imgui/bgfx/hello_triangle_drawer.h b/examples/render/04-hello-triangle-imgui/bgfx/hello_triangle_drawer.h new file mode 100644 index 000000000..063dbd61e --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/hello_triangle_drawer.h @@ -0,0 +1,71 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef HELLO_TRIANGLE_DRAWER_H +#define HELLO_TRIANGLE_DRAWER_H + +#include "common.h" + +#include + +template +class HelloTriangleDrawer : public vcl::PlainDrawer +{ +public: + HelloTriangleDrawer(vcl::uint width = 1024, vcl::uint height = 768) {} + + ~HelloTriangleDrawer() + { + if (bgfx::isValid(vbh)) + bgfx::destroy(vbh); + if (bgfx::isValid(program)) + bgfx::destroy(program); + } + + void onInit(vcl::uint viewId) override + { + setUpBGFX(viewId, vbh, program); + } + + void onResize(vcl::uint width, vcl::uint height) override + { + std::cout << "Resize: " << width << "; " << height + << ". Nothing to do\n"; + } + + void onDrawContent(vcl::uint viewId) override + { + drawOnView(viewId, vbh, program); + } + + void onDraw(vcl::uint viewId) override + { + onDrawContent(viewId); + } + +private: + bgfx::VertexBufferHandle vbh; + + bgfx::ProgramHandle program; +}; + +#endif // HELLO_TRIANGLE_DRAWER_H diff --git a/examples/render/04-hello-triangle-imgui/bgfx/qt/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/bgfx/qt/CMakeLists.txt new file mode 100644 index 000000000..6dcffa480 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/qt/CMakeLists.txt @@ -0,0 +1,47 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +set(EXAMPLE_NAME 00-hello-triangle-qt) +project(vclib-render-example-${EXAMPLE_NAME}) + +### Build settings +set(CMAKE_CXX_STANDARD 20) + +set(HEADERS + ../common.h + ../hello_triangle_drawer.h) + +set(SOURCES + main.cpp) + +set(SHADERS + shaders/vs_vertex_shader.sc + shaders/fs_fragment_shader.sc + shaders/varying.def.sc) + +vclib_add_example(${EXAMPLE_NAME} + VCLIB_MODULE render + SOURCES ${HEADERS} ${SOURCES}) + +target_add_bgfx_shaders(${PROJECT_NAME} ${SHADERS}) diff --git a/examples/render/04-hello-triangle-imgui/bgfx/qt/main.cpp b/examples/render/04-hello-triangle-imgui/bgfx/qt/main.cpp new file mode 100644 index 000000000..9e8f36bee --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/qt/main.cpp @@ -0,0 +1,43 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#include "../hello_triangle_drawer.h" + +#include +#include +#include + +#include + +int main(int argc, char** argv) +{ + QApplication app(argc, argv); + + using WidgetQt = vcl:: + RenderApp; + + WidgetQt tw("Hello Triangle with Qt"); + + tw.show(); + + return app.exec(); +} diff --git a/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/fs_fragment_shader.sc b/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/fs_fragment_shader.sc new file mode 100644 index 000000000..fd4cbb186 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/fs_fragment_shader.sc @@ -0,0 +1,8 @@ +$input v_color + +#include + +void main() +{ + gl_FragColor = v_color; +} diff --git a/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/varying.def.sc b/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/varying.def.sc new file mode 100644 index 000000000..ec1306b83 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/varying.def.sc @@ -0,0 +1,4 @@ +vec2 a_position : POSITION; +vec4 a_color0 : COLOR0; + +vec4 v_color : COLOR0; diff --git a/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/vs_vertex_shader.sc b/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/vs_vertex_shader.sc new file mode 100644 index 000000000..581eaeb7d --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/bgfx/qt/shaders/vs_vertex_shader.sc @@ -0,0 +1,12 @@ +$input a_position +$input a_color0 + +$output v_color + +#include + +void main() +{ + gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); + v_color = a_color0; +} diff --git a/examples/render/04-hello-triangle-imgui/demo_imgui_drawer.h b/examples/render/04-hello-triangle-imgui/demo_imgui_drawer.h new file mode 100644 index 000000000..b59d26a33 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/demo_imgui_drawer.h @@ -0,0 +1,28 @@ +#ifndef DEMO_IMGUI_DRAWER_H +#define DEMO_IMGUI_DRAWER_H + +#include + +#include + +template +class DemoImGuiDrawer : public vcl::imgui::ImGuiDrawer +{ + using ParentDrawer = vcl::imgui::ImGuiDrawer; + +public: + using ParentDrawer::ParentDrawer; + + virtual void onDraw(vcl::uint viewId) override + { + // draw the scene + ParentDrawer::onDraw(viewId); + + if (!ParentDrawer::isWindowMinimized()) { + // imgui demo window + ImGui::ShowDemoWindow(); + } + } +}; + +#endif // DEMO_IMGUI_DRAWER_H diff --git a/examples/render/04-hello-triangle-imgui/opengl2/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/opengl2/CMakeLists.txt new file mode 100644 index 000000000..e9a8dd681 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/CMakeLists.txt @@ -0,0 +1,30 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +if (TARGET vclib-3rd-glfw) + add_subdirectory(glfw) +endif() +if (TARGET vclib-3rd-qt) + #add_subdirectory(qt) +endif() diff --git a/examples/render/04-hello-triangle-imgui/opengl2/common.h b/examples/render/04-hello-triangle-imgui/opengl2/common.h new file mode 100644 index 000000000..308428b91 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/common.h @@ -0,0 +1,49 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef COMMON_H +#define COMMON_H + +#include + +#ifdef __APPLE__ +#include +#else +#ifdef _WIN32 +#include +#endif +#include +#endif + +struct Vertex +{ + float pos[2]; + uint32_t abgr; +}; + +static const Vertex vertices[] { + {{-1.0f, -1.0f}, vcl::Color(vcl::Color::Red).abgr() }, + {{1.0f, -1.0f}, vcl::Color(vcl::Color::Green).abgr()}, + {{0.0f, 1.0f}, vcl::Color(vcl::Color::Blue).abgr() }, +}; + +#endif // COMMON_H diff --git a/examples/render/04-hello-triangle-imgui/opengl2/glfw/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/opengl2/glfw/CMakeLists.txt new file mode 100644 index 000000000..e3d0f2efa --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/glfw/CMakeLists.txt @@ -0,0 +1,41 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +set(EXAMPLE_NAME 04-hello-triangle-imgui-glfw) +project(vclib-render-example-${EXAMPLE_NAME}) + +### Build settings +set(CMAKE_CXX_STANDARD 20) + +set(HEADERS + ../common.h + ../hello_triangle_drawer.h + ../../demo_imgui_drawer.h) + +set(SOURCES + main.cpp) + +vclib_add_example(${EXAMPLE_NAME} + VCLIB_MODULE render + SOURCES ${HEADERS} ${SOURCES}) diff --git a/examples/render/04-hello-triangle-imgui/opengl2/glfw/main.cpp b/examples/render/04-hello-triangle-imgui/opengl2/glfw/main.cpp new file mode 100644 index 000000000..543195a0f --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/glfw/main.cpp @@ -0,0 +1,51 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#include "../../demo_imgui_drawer.h" +#include "../hello_triangle_drawer.h" + +#include +#include +#include + +/** + * This Demo is a simple example of how to use the ImGuiDrawer to draw the ImGui + * demo window. + * + * The example is the same as 00-hello-triangle, but with the addition of the + * ImGui demo window. + */ +int main(int argc, char** argv) +{ + // The window is created with the RenderApp class: + using WindowGLFW = vcl::RenderApp< + vcl::glfw::WindowManager, // The WindowManager: GLFW + vcl::Canvas, // The default Canvas + DemoImGuiDrawer, // A Drawer that draws the ImGui demo window + HelloTriangleDrawer>; // The Drawer that draws the triangle + + WindowGLFW tw("Hello Triangle ImGui with GLFW"); + + tw.show(); + + return 0; +} diff --git a/examples/render/04-hello-triangle-imgui/opengl2/hello_triangle_drawer.h b/examples/render/04-hello-triangle-imgui/opengl2/hello_triangle_drawer.h new file mode 100644 index 000000000..04c953145 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/hello_triangle_drawer.h @@ -0,0 +1,62 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2024 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef HELLO_TRIANGLE_DRAWER_H +#define HELLO_TRIANGLE_DRAWER_H + +#include "common.h" + +#include + +template +class HelloTriangleDrawer : public vcl::PlainDrawer +{ +public: + HelloTriangleDrawer(vcl::uint width = 1024, vcl::uint height = 768) {} + + ~HelloTriangleDrawer() + { + } + + void onResize(vcl::uint width, vcl::uint height) override + { + std::cout << "Resize: " << width << "; " << height + << ". Nothing to do\n"; + } + + void onDrawContent(vcl::uint) override + { + glClearColor(0.f, 0.f, 0.f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + glColor4ubv((GLubyte*) &(vertices[0].abgr)); + glVertex2fv((GLfloat*) &(vertices[0].pos)); + glColor4ubv((GLubyte*) &(vertices[1].abgr)); + glVertex2fv((GLfloat*) &(vertices[1].pos)); + glColor4ubv((GLubyte*) &(vertices[2].abgr)); + glVertex2fv((GLfloat*) &(vertices[2].pos)); + glEnd(); + } +}; + +#endif // HELLO_TRIANGLE_DRAWER_H diff --git a/examples/render/04-hello-triangle-imgui/opengl2/qt/CMakeLists.txt b/examples/render/04-hello-triangle-imgui/opengl2/qt/CMakeLists.txt new file mode 100644 index 000000000..feba451b9 --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/qt/CMakeLists.txt @@ -0,0 +1,40 @@ +#***************************************************************************** +#* VCLib * +#* Visual Computing Library * +#* * +#* Copyright(C) 2021-2025 * +#* Visual Computing Lab * +#* ISTI - Italian National Research Council * +#* * +#* All rights reserved. * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the Mozilla Public License Version 2.0 as published * +#* by the Mozilla Foundation; either version 2 of the License, or * +#* (at your option) any later version. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* Mozilla Public License Version 2.0 * +#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * +#****************************************************************************/ + +cmake_minimum_required(VERSION 3.24) + +set(EXAMPLE_NAME 00-hello-triangle-qt) +project(vclib-render-example-${EXAMPLE_NAME}) + +### Build settings +set(CMAKE_CXX_STANDARD 20) + +set(HEADERS + ../common.h + ../hello_triangle_drawer.h) + +set(SOURCES + main.cpp) + +vclib_add_example(${EXAMPLE_NAME} + VCLIB_MODULE render + SOURCES ${HEADERS} ${SOURCES}) diff --git a/examples/render/04-hello-triangle-imgui/opengl2/qt/main.cpp b/examples/render/04-hello-triangle-imgui/opengl2/qt/main.cpp new file mode 100644 index 000000000..678b1be9d --- /dev/null +++ b/examples/render/04-hello-triangle-imgui/opengl2/qt/main.cpp @@ -0,0 +1,44 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#include "../hello_triangle_drawer.h" + +#include +#include +#include + +#include + +int main(int argc, char** argv) +{ + QApplication app(argc, argv); + + using WidgetQt = vcl:: + RenderApp; + + WidgetQt tw("Hello Triangle with Qt"); + + tw.show(); + + return app.exec(); +} + diff --git a/examples/render/CMakeLists.txt b/examples/render/CMakeLists.txt index 5dd8ed8ba..bc00efc63 100644 --- a/examples/render/CMakeLists.txt +++ b/examples/render/CMakeLists.txt @@ -42,6 +42,7 @@ add_subdirectory(00-hello-triangle) add_subdirectory(01-viewer) add_subdirectory(02-mesh-viewer) add_subdirectory(03-viewer-with-text) +add_subdirectory(04-hello-triangle-imgui) if (TARGET vclib-processing) add_subdirectory(800-processing-main-window)