Skip to content

Commit 213b58d

Browse files
committed
Merge branch 'render-dev'
2 parents dc074d1 + 3c65c63 commit 213b58d

32 files changed

+1809
-19
lines changed

examples/render/00-hello-triangle/opengl2/glfw/hello_triangle_glfw.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,4 @@ void HelloTriangleGLFW::drawContent()
4848
glColor4ubv((GLubyte*) &(vertices[2].abgr));
4949
glVertex2fv((GLfloat*) &(vertices[2].pos));
5050
glEnd();
51-
52-
glfwSwapBuffers(mWindow);
5351
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#*****************************************************************************
2+
#* VCLib *
3+
#* Visual Computing Library *
4+
#* *
5+
#* Copyright(C) 2021-2024 *
6+
#* Visual Computing Lab *
7+
#* ISTI - Italian National Research Council *
8+
#* *
9+
#* All rights reserved. *
10+
#* *
11+
#* This program is free software; you can redistribute it and/or modify *
12+
#* it under the terms of the Mozilla Public License Version 2.0 as published *
13+
#* by the Mozilla Foundation; either version 2 of the License, or *
14+
#* (at your option) any later version. *
15+
#* *
16+
#* This program is distributed in the hope that it will be useful, *
17+
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18+
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19+
#* Mozilla Public License Version 2.0 *
20+
#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21+
#****************************************************************************/
22+
23+
cmake_minimum_required(VERSION 3.24)
24+
25+
set(EXAMPLE_NAME 910-viewer-glfw-imgui)
26+
project(vclib-render-example-${EXAMPLE_NAME})
27+
28+
### Build settings
29+
set(CMAKE_CXX_STANDARD 20)
30+
31+
set(HEADERS
32+
common.h)
33+
34+
set(SOURCES
35+
main.cpp)
36+
37+
# will create a target called 'vclib-render-example-${EXAMPLE_NAME}'
38+
vclib_add_example(${EXAMPLE_NAME}
39+
VCLIB_MODULE render
40+
SOURCES ${HEADERS} ${SOURCES})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*****************************************************************************
2+
* VCLib *
3+
* Visual Computing Library *
4+
* *
5+
* Copyright(C) 2021-2024 *
6+
* Visual Computing Lab *
7+
* ISTI - Italian National Research Council *
8+
* *
9+
* All rights reserved. *
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 3 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
* This program is distributed in the hope that it will be useful, *
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19+
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20+
* for more details. *
21+
****************************************************************************/
22+
23+
#ifndef COMMON_H
24+
#define COMMON_H
25+
26+
#include <vclib/algorithms/mesh/update/color.h>
27+
#include <vclib/algorithms/mesh/update/normal.h>
28+
#include <vclib/load_save.h>
29+
#include <vclib/meshes/tri_mesh.h>
30+
31+
#include <vclib/render/drawable/drawable_mesh.h>
32+
33+
inline vcl::DrawableMesh<vcl::TriMesh> getDrawableMesh(
34+
const std::string& filename = "bimba.obj")
35+
{
36+
// load a mesh:
37+
vcl::TriMesh m =
38+
vcl::load<vcl::TriMesh>(VCLIB_EXAMPLE_MESHES_PATH "/" + filename);
39+
vcl::updatePerVertexAndFaceNormals(m);
40+
41+
// enable the vertex color of the mesh and set it to gray
42+
m.enablePerVertexColor();
43+
vcl::setPerVertexColor(m, vcl::Color::Gray);
44+
45+
// create a MeshRenderSettings object, that allows to set the rendering
46+
// options of the mesh
47+
// default is what we want: color per vertex, smooth shading, no wireframe
48+
vcl::MeshRenderSettings settings(m);
49+
50+
// create a DrawableMesh object from the mesh
51+
vcl::DrawableMesh<vcl::TriMesh> drawable(m);
52+
53+
// set the settings to the drawable mesh
54+
drawable.setRenderSettings(settings);
55+
56+
return drawable;
57+
}
58+
59+
#endif // COMMON_H
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*****************************************************************************
2+
* VCLib *
3+
* Visual Computing Library *
4+
* *
5+
* Copyright(C) 2021-2024 *
6+
* Visual Computing Lab *
7+
* ISTI - Italian National Research Council *
8+
* *
9+
* All rights reserved. *
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 3 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
* This program is distributed in the hope that it will be useful, *
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19+
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20+
* for more details. *
21+
****************************************************************************/
22+
23+
#include "common.h"
24+
25+
#include <vclib/glfw_imgui/viewer_window_imgui.h>
26+
#include <imgui.h>
27+
28+
class ImguiDemo : public vcl::glfw::ViewerWindowImgui
29+
{
30+
public:
31+
ImguiDemo(const std::string& windowTitle) : ViewerWindowImgui(windowTitle)
32+
{
33+
}
34+
35+
void draw() override
36+
{
37+
// imgui demo window
38+
ImGui::ShowDemoWindow();
39+
40+
// draw the scene
41+
ViewerWindowImgui::draw();
42+
}
43+
};
44+
45+
int main(int argc, char** argv)
46+
{
47+
ImguiDemo tw("Viewer GLFW");
48+
49+
// load and set up a drawable mesh
50+
vcl::DrawableMesh<vcl::TriMesh> drawable = getDrawableMesh();
51+
52+
// add the drawable mesh to the scene
53+
// the viewer will own **a copy** of the drawable mesh
54+
tw.pushDrawableObject(drawable);
55+
56+
tw.fitScene();
57+
58+
tw.show();
59+
60+
return 0;
61+
}

examples/render/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ if (TARGET vclib-processing)
4747
add_subdirectory(800-processing-main-window)
4848
endif()
4949

50+
if(TARGET vclib-3rd-imgui AND TARGET vclib-3rd-glfw)
51+
add_subdirectory(910-viewer-imgui)
52+
endif()
53+
5054
add_subdirectory(999-misc)
5155

5256
if (CAN_BUILD_VCLIB_EXAMPLES)

vclib/render/3rdparty/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ option(VCLIB_ALLOW_SYSTEM_QT "Allow use of system-provided Qt" ON)
4545
option(VCLIB_ALLOW_SYSTEM_GLFW "Allow use of system-provided GLFW" ON)
4646
option(VCLIB_ALLOW_DOWNLOAD_GLFW "Allow use of downloaded GLFW source" ON)
4747

48+
# ImGui
49+
option(VCLIB_ALLOW_DOWNLOAD_IMGUI "Allow use of downloaded ImGui source" ON)
50+
4851
set(VCLIB_RENDER_3RDPARTY_LIBRARIES "")
4952

5053
# === RENDER ENGINES (and optional libraries binded to them) === #
@@ -70,5 +73,8 @@ include(qt.cmake)
7073
### GLFW
7174
include(glfw.cmake)
7275

76+
### ImGui
77+
include(imgui.cmake)
78+
7379
set(VCLIB_RENDER_3RDPARTY_LIBRARIES
7480
${VCLIB_RENDER_3RDPARTY_LIBRARIES} PARENT_SCOPE)

vclib/render/3rdparty/imgui.cmake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#*****************************************************************************
2+
#* VCLib *
3+
#* Visual Computing Library *
4+
#* *
5+
#* Copyright(C) 2021-2024 *
6+
#* Visual Computing Lab *
7+
#* ISTI - Italian National Research Council *
8+
#* *
9+
#* All rights reserved. *
10+
#* *
11+
#* This program is free software; you can redistribute it and/or modify *
12+
#* it under the terms of the Mozilla Public License Version 2.0 as published *
13+
#* by the Mozilla Foundation; either version 2 of the License, or *
14+
#* (at your option) any later version. *
15+
#* *
16+
#* This program is distributed in the hope that it will be useful, *
17+
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18+
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19+
#* Mozilla Public License Version 2.0 *
20+
#* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21+
#****************************************************************************/
22+
23+
if (VCLIB_ALLOW_DOWNLOAD_IMGUI)
24+
message(STATUS "- ImGui - using downloaded source")
25+
26+
# ImGui (glfw + bgfx)
27+
FetchContent_Declare(
28+
imgui
29+
GIT_REPOSITORY https://github.com/ocornut/imgui.git
30+
GIT_TAG master
31+
)
32+
FetchContent_MakeAvailable(imgui)
33+
34+
file(GLOB IMGUI_SOURCES ${imgui_SOURCE_DIR}/*.cpp ${imgui_SOURCE_DIR}/*.h)
35+
add_library(imgui STATIC
36+
${IMGUI_SOURCES}
37+
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp # TODO: std::string? check
38+
)
39+
if (TARGET vclib-3rd-glfw)
40+
target_sources(imgui PRIVATE
41+
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
42+
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.h)
43+
endif()
44+
45+
if (VCLIB_RENDER_BACKEND STREQUAL "opengl2")
46+
target_sources(imgui PRIVATE
47+
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.cpp
48+
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.h
49+
)
50+
endif()
51+
52+
target_link_libraries(imgui PRIVATE glfw)
53+
target_include_directories(imgui PUBLIC
54+
${imgui_SOURCE_DIR}
55+
${imgui_SOURCE_DIR}/misc/cpp
56+
${imgui_SOURCE_DIR}/backends
57+
)
58+
# this is the way to include the custom imconfig.h
59+
# target_compile_definitions(imgui PRIVATE IMGUI_USER_CONFIG="<vclib/bgfx/imgui/imconfig.h>")
60+
61+
# add -fPIC flag to imgui target
62+
set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE ON)
63+
64+
add_library(vclib-3rd-imgui INTERFACE)
65+
target_link_libraries(vclib-3rd-imgui INTERFACE imgui)
66+
67+
list(APPEND VCLIB_RENDER_3RDPARTY_LIBRARIES vclib-3rd-imgui)
68+
endif()

vclib/render/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ if (VCLIB_RENDER_BACKEND STREQUAL "bgfx")
6565
file(GLOB_RECURSE SHADERS_BGFX CONFIGURE_DEPENDS
6666
"shaders/vclib/bgfx/*.sh" "shaders/vclib/bgfx/*.sc")
6767
list(APPEND SHADERS ${SHADERS_BGFX})
68+
69+
if (TARGET vclib-3rd-imgui)
70+
file(GLOB_RECURSE HEADERS_BGFX_IMGUI CONFIGURE_DEPENDS
71+
"include/vclib/bgfx_imgui/*.h")
72+
list(APPEND HEADERS ${HEADERS_BGFX_IMGUI})
73+
74+
file(GLOB_RECURSE SOURCES_BGFX_IMGUI CONFIGURE_DEPENDS
75+
"src/vclib/bgfx_imgui/*.cpp")
76+
list(APPEND SOURCES ${SOURCES_BGFX_IMGUI})
77+
78+
file(GLOB_RECURSE SHADERS_BGFX_IMGUI CONFIGURE_DEPENDS
79+
"shaders/vclib/bgfx_imgui/*.sh" "shaders/vclib/bgfx_imgui/*.sc")
80+
list(APPEND SHADERS ${SHADERS_BGFX_IMGUI})
81+
endif()
6882
endif()
6983

7084
# if render engine is opengl2 - include sources that use opengl2
@@ -85,6 +99,16 @@ if (TARGET vclib-3rd-glfw)
8599

86100
file(GLOB_RECURSE SOURCES_GLFW CONFIGURE_DEPENDS "src/vclib/glfw/*.cpp")
87101
list(APPEND SOURCES ${SOURCES_GLFW})
102+
103+
if (TARGET vclib-3rd-imgui)
104+
file(GLOB_RECURSE HEADERS_GLFW_IMGUI CONFIGURE_DEPENDS
105+
"include/vclib/glfw_imgui/*.h")
106+
list(APPEND HEADERS ${HEADERS_GLFW_IMGUI})
107+
108+
file(GLOB_RECURSE SOURCES_GLFW_IMGUI CONFIGURE_DEPENDS
109+
"src/vclib/glfw_imgui/*.cpp")
110+
list(APPEND SOURCES ${SOURCES_GLFW_IMGUI})
111+
endif()
88112
endif()
89113

90114
if (TARGET vclib-3rd-qt)

vclib/render/include/vclib/bgfx/canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class CanvasBGFX : public virtual vcl::EventManagerI
142142

143143
void onResize(uint width, uint height) override;
144144

145-
void frame();
145+
virtual void frame();
146146

147147
private:
148148
// draw offscreen frame
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The source code of this directory is directly taken from the [bgfx repository](https://github.com/bkaradzic/bgfx), and it is licensed under the BSD 2-Clause License.
22

33
It has been modified with the following goals:
4-
- Remove the dependency on the bgfx example-common library, that is not needed for the purpose of this project and it depends on ImGui, that is not used/needed in this project.
4+
- Remove the dependency on the bgfx example-common library, that is not needed for the purpose of this project and it depends on ImGui.
55
- Insert the original classes and functions under bgfx namespace, to avoid conflicts with other libraries.
66
- Use the vclib-render stb-TrueType library instead of the one used by bgfx
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"DisableFormat": true,
3+
"SortIncludes": "Never"
4+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright 2010-2024 Branimir Karadzic
2+
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
22+
OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The source code of this is modified starting from the [bgfx repository](https://github.com/bkaradzic/bgfx), and it is licensed under the BSD 2-Clause License.
2+
3+
It has been modified mainly with the following goals:
4+
- provide a 'standard' implementation of a bgfx backend for ImGui;
5+
- Remove the dependency on the bgfx example-common library;
6+
- Use the vclib-render stb-TrueType library instead of the one used by bgfx

0 commit comments

Comments
 (0)