Skip to content

Commit 1166702

Browse files
committed
Merge branch '2019_updates'
2 parents 4deb28d + e428482 commit 1166702

34 files changed

+435
-8381
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
image:
22
- Visual Studio 2017
3-
- Visual Studio 2019 Preview
3+
- Visual Studio 2019
44

55
platform:
66
- x64

CHANGES.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Revision history for CG_Labs
2+
3+
4+
v2019.1 YYYY-MM-DD
5+
==================
6+
7+
* Add a “CHANGES.rst” file that will list the different modifications done,
8+
from now on.
9+
* Ensure Log is destroyed before its clients (GitLab #45)
10+
* Unify the TRS interfaces between the node and the TRSTransform classes, by
11+
using and exposing a TRSTransform instance inside the node class (GitLab #46)
12+
* Select polygon mode from GUI, and simplify it (GitLab #47)
13+
* Toggle visualisation of light cones in wireframe mode from the GUI
14+
* Switch between shaders from GUI (GitLab #48)
15+
* Edit node::render() to take parent transform
16+
* Rename `WindowManager::CreateWindow()` to
17+
`WindowManager::CreateGLFWWindow()`, to avoid conflict with Windows API
18+
macro.
19+
* Replace lodepng with stb, to also support JPEG file loading (GitLab #41)
20+
* Add shader for celestial rings and load it in lab1 (GitLab #51)
21+
* AppVeyor: switch from VS 2019 Preview to VS 2019
22+
* README: Add tinyfiledialogs to dependencies
23+
* (HEAD -> 2019_updates) README: Sort the list of dependencies

CMake/InstallSTB.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set (stb_SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/stb-source)
2+
3+
if (NOT EXISTS ${stb_SOURCE_DIR})
4+
message (STATUS "Cloning stb…")
5+
execute_process (
6+
COMMAND ${GIT_EXECUTABLE} clone --depth=1
7+
https://github.com/nothings/stb
8+
${stb_SOURCE_DIR}
9+
OUTPUT_QUIET
10+
ERROR_VARIABLE stderr
11+
RESULT_VARIABLE result
12+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies
13+
)
14+
if (result)
15+
message (FATAL_ERROR "Failed to clone stb: ${result}\n"
16+
"Error output: ${stderr}")
17+
endif ()
18+
endif ()
19+
20+
add_library( stb::stb INTERFACE IMPORTED)
21+
set_target_properties(stb::stb PROPERTIES
22+
INTERFACE_INCLUDE_DIRECTORIES "${stb_SOURCE_DIR}"
23+
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c"
24+
)

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif ()
1414
# Set the project name, versions and languages used.
1515
project (
1616
CG_Labs
17-
VERSION 0.1
17+
VERSION 2019.1
1818
LANGUAGES CXX C
1919
)
2020

@@ -65,6 +65,9 @@ find_package (imgui ${LUGGCGL_IMGUI_MIN_VERSION} REQUIRED)
6565
# TinyFileDialogs is used for displaying error popups.
6666
include (CMake/InstallTinyFileDialogs.cmake)
6767

68+
# stb is used for loading in image files.
69+
include (CMake/InstallSTB.cmake)
70+
6871
# Resources are found in an external archive
6972
include (CMake/RetrieveResourceArchive.cmake)
7073

@@ -124,7 +127,7 @@ function (luggcgl_new_assignment assignment_name sources common_sources)
124127

125128
add_dependencies (${assignment_name} bonobo)
126129

127-
target_link_libraries (${assignment_name} bonobo imgui::imgui glm tinyfiledialogs::tinyfiledialogs)
130+
target_link_libraries (${assignment_name} bonobo imgui::imgui glm stb::stb tinyfiledialogs::tinyfiledialogs)
128131

129132
install (TARGETS ${assignment_name} DESTINATION bin)
130133
endfunction ()
@@ -145,7 +148,6 @@ endfunction ()
145148

146149
# Define groups of files for IDEs
147150
set (PATH_SEP \\)
148-
source_group (Source\ Files${PATH_SEP}External${PATH_SEP}lodepng FILES ${PROJECT_SOURCE_DIR}/src/lodepng.cpp ${PROJECT_SOURCE_DIR}/src/external/lodepng.h)
149151
source_group (Source\ Files${PATH_SEP}External${PATH_SEP}GLFW FILES ${PROJECT_SOURCE_DIR}/src/external/imgui_impl_glfw_gl3.cpp ${PROJECT_SOURCE_DIR}/src/external/imgui_impl_glfw_gl3.h)
150152
source_group (Source\ Files${PATH_SEP}External${PATH_SEP}GL3W FILES ${PROJECT_SOURCE_DIR}/src/external/gl3w.cpp)
151153

README.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ Dependencies
1616

1717
CG_Labs uses the following dependencies:
1818

19+
* assimp_ (>= 4.1.0): to load OBJ models;
1920
* CMake_ (>= 3.0): to generate project files and handle dependencies;
21+
* `Dear ImGui`_ (>= 1.51): to display information on screen, such as logs;
2022
* Git_: to clone missing dependencies;
21-
* GLFW_ (>= 3.2.1): to create a window and an OpenGL context, as well as handle inputs;
2223
* GLAD_: to load OpenGL extensions;
24+
* GLFW_ (>= 3.2.1): to create a window and an OpenGL context, as well as handle inputs;
2325
* GLM_ (>= 0.9.8.5): for linear algebra operations;
24-
* `Dear ImGui`_ (>= 1.51): to display information on screen, such as logs;
25-
* assimp_ (>= 4.1.0): to load OBJ models;
26-
* lodepng_: to load PNG files;
26+
* stb_: to load image files;
27+
* tinyfiledialogs_: to display dialogue windows to the user, in case of errors
28+
for example.
2729

28-
The project contains the needed files for GLAD and lodepng, and it will
29-
download assimp, Dear ImGui, GLM and GLFW if they are not found on your
30+
The project contains the needed files for GLAD, and it will download assimp,
31+
Dear ImGui, GLM, GLFW, stb and tinyfiledialogs if they are not found on your
3032
computer, so you only need to make sure that CMake and Git are installed on
3133
your computer.
3234

@@ -122,7 +124,6 @@ Licence
122124
=======
123125

124126
* Dear ImGui is released under an MIT licence, see `Dear ImGui’s licence`_.
125-
* lodepng’s licence can be found at the top of every lodepng file.
126127
* This project is unlicenced, see `the UNLICENCE file`_.
127128

128129
.. _Lund University: http://www.lu.se/
@@ -135,7 +136,8 @@ Licence
135136
.. _GLM: http://glm.g-truc.net/
136137
.. _Dear ImGui: https://github.com/ocornut/imgui
137138
.. _assimp: https://github.com/assimp/assimp
138-
.. _lodepng: http://lodev.org/lodepng/
139+
.. _stb: https://github.com/nothings/stb
140+
.. _tinyfiledialogs: https://sourceforge.net/projects/tinyfiledialogs/
139141
.. _cmake-generators(7): https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html
140142
.. _Dear ImGui’s licence: Dear_ImGui_LICENCE
141143
.. _this ZIP file: http://fileadmin.cs.lth.se/cs/Education/EDA221/assignments/EDA221_resources.zip

shaders/EDAF80/celestial_ring.frag

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#version 410
2+
3+
uniform sampler2D diffuse_texture;
4+
uniform sampler2D opacity_texture;
5+
uniform int has_diffuse_texture;
6+
uniform int has_opacity_texture;
7+
8+
in VS_OUT {
9+
vec2 texcoord;
10+
} fs_in;
11+
12+
out vec4 frag_color;
13+
14+
void main()
15+
{
16+
float alpha = 1.0f;
17+
if (has_opacity_texture != 0) {
18+
alpha = texture(opacity_texture,
19+
vec2(1.0f - fs_in.texcoord.x, fs_in.texcoord.y)).r;
20+
if (alpha == 0.0f)
21+
discard;
22+
}
23+
24+
if (has_diffuse_texture != 0)
25+
frag_color = texture(diffuse_texture, fs_in.texcoord);
26+
else
27+
frag_color = vec4(1.0);
28+
29+
frag_color *= alpha;
30+
}

shaders/EDAF80/celestial_ring.vert

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#version 410
2+
3+
layout (location = 0) in vec3 vertex;
4+
layout (location = 2) in vec3 texcoord;
5+
6+
uniform mat4 vertex_model_to_world;
7+
uniform mat4 vertex_world_to_clip;
8+
9+
out VS_OUT {
10+
vec2 texcoord;
11+
} vs_out;
12+
13+
14+
void main()
15+
{
16+
vs_out.texcoord = vec2(texcoord.x, texcoord.y);
17+
18+
gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(vertex, 1.0);
19+
}

src/EDAF80/assignment1.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include "config.hpp"
2+
#include "parametric_shapes.hpp"
3+
#include "core/Bonobo.h"
24
#include "core/FPSCamera.h"
35
#include "core/helpers.hpp"
4-
#include "core/Log.h"
5-
#include "core/LogView.h"
66
#include "core/Misc.h"
77
#include "core/node.hpp"
88
#include "core/ShaderProgramManager.hpp"
9-
#include "core/WindowManager.hpp"
109

1110
#include <imgui.h>
1211
#include <external/imgui_impl_glfw_gl3.h>
@@ -19,10 +18,9 @@
1918
int main()
2019
{
2120
//
22-
// Set up the logging system
21+
// Set up the framework
2322
//
24-
Log::Init();
25-
Log::View::Init();
23+
Bonobo framework;
2624

2725
//
2826
// Set up the camera
@@ -36,17 +34,14 @@ int main()
3634
camera.mMovementSpeed = 0.25f * 12.0f;
3735

3836
//
39-
// Set up the windowing system and create the window
37+
// Create the window
4038
//
41-
WindowManager window_manager;
39+
WindowManager& window_manager = framework.GetWindowManager();
4240
WindowManager::WindowDatum window_datum{ input_handler, camera, config::resolution_x, config::resolution_y, 0, 0, 0, 0};
43-
GLFWwindow* window = window_manager.CreateWindow("EDAF80: Assignment 1", window_datum, config::msaa_rate);
41+
GLFWwindow* window = window_manager.CreateGLFWWindow("EDAF80: Assignment 1", window_datum, config::msaa_rate);
4442
if (window == nullptr) {
4543
LogError("Failed to get a window: exiting.");
4644

47-
Log::View::Destroy();
48-
Log::Destroy();
49-
5045
return EXIT_FAILURE;
5146
}
5247

@@ -57,9 +52,6 @@ int main()
5752
if (objects.empty()) {
5853
LogError("Failed to load the sphere geometry: exiting.");
5954

60-
Log::View::Destroy();
61-
Log::Destroy();
62-
6355
return EXIT_FAILURE;
6456
}
6557
bonobo::mesh_data const& sphere = objects.front();
@@ -69,12 +61,26 @@ int main()
6961
// Create the shader program
7062
//
7163
ShaderProgramManager program_manager;
72-
GLuint shader = 0u;
73-
program_manager.CreateAndRegisterProgram({ { ShaderType::vertex, "EDAF80/default.vert" },
64+
GLuint celestial_body_shader = 0u;
65+
program_manager.CreateAndRegisterProgram("Celestial Body",
66+
{ { ShaderType::vertex, "EDAF80/default.vert" },
7467
{ ShaderType::fragment, "EDAF80/default.frag" } },
75-
shader);
76-
if (shader == 0u) {
77-
LogError("Failed to generate the shader program: exiting.");
68+
celestial_body_shader);
69+
if (celestial_body_shader == 0u) {
70+
LogError("Failed to generate the “Celestial Body” shader program: exiting.");
71+
72+
Log::View::Destroy();
73+
Log::Destroy();
74+
75+
return EXIT_FAILURE;
76+
}
77+
GLuint celestial_ring_shader = 0u;
78+
program_manager.CreateAndRegisterProgram("Celestial Ring",
79+
{ { ShaderType::vertex, "EDAF80/celestial_ring.vert" },
80+
{ ShaderType::fragment, "EDAF80/celestial_ring.frag" } },
81+
celestial_ring_shader);
82+
if (celestial_ring_shader == 0u) {
83+
LogError("Failed to generate the “Celestial Ring” shader program: exiting.");
7884

7985
Log::View::Destroy();
8086
Log::Destroy();
@@ -88,6 +94,8 @@ int main()
8894
//
8995
Node sun_node;
9096
sun_node.set_geometry(sphere);
97+
sun_node.set_program(&celestial_body_shader, [](GLuint /*program*/){});
98+
TRSTransformf& sun_transform_reference = sun_node.get_transform();
9199
GLuint const sun_texture = bonobo::loadTexture2D("sunmap.png");
92100
sun_node.add_texture("diffuse_texture", sun_texture, GL_TEXTURE_2D);
93101
float const sun_spin_speed = glm::two_pi<float>() / 6.0f; // Full rotation in six seconds
@@ -168,7 +176,7 @@ int main()
168176
//
169177
// Update the transforms
170178
//
171-
sun_node.rotate_y(sun_spin_speed * delta_time);
179+
sun_transform_reference.RotateY(sun_spin_speed * delta_time);
172180

173181

174182
//
@@ -178,7 +186,7 @@ int main()
178186
std::stack<glm::mat4> matrix_stack({ glm::mat4(1.0f) });
179187
// TODO: Replace this explicit rendering of the Sun with a
180188
// traversal of the scene graph and rendering of all its nodes.
181-
sun_node.render(camera.GetWorldToClipMatrix(), sun_node.get_transform(), shader, [](GLuint /*program*/){});
189+
sun_node.render(camera.GetWorldToClipMatrix());
182190

183191

184192
//
@@ -198,9 +206,5 @@ int main()
198206

199207
glDeleteTextures(1, &sun_texture);
200208

201-
202-
Log::View::Destroy();
203-
Log::Destroy();
204-
205209
return EXIT_SUCCESS;
206210
}

0 commit comments

Comments
 (0)