Skip to content

Commit

Permalink
Merge branch '2019_updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
pierremoreau committed Sep 6, 2019
2 parents 4deb28d + e428482 commit 1166702
Show file tree
Hide file tree
Showing 34 changed files with 435 additions and 8,381 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image:
- Visual Studio 2017
- Visual Studio 2019 Preview
- Visual Studio 2019

platform:
- x64
Expand Down
23 changes: 23 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Revision history for CG_Labs


v2019.1 YYYY-MM-DD
==================

* Add a “CHANGES.rst” file that will list the different modifications done,
from now on.
* Ensure Log is destroyed before its clients (GitLab #45)
* Unify the TRS interfaces between the node and the TRSTransform classes, by
using and exposing a TRSTransform instance inside the node class (GitLab #46)
* Select polygon mode from GUI, and simplify it (GitLab #47)
* Toggle visualisation of light cones in wireframe mode from the GUI
* Switch between shaders from GUI (GitLab #48)
* Edit node::render() to take parent transform
* Rename `WindowManager::CreateWindow()` to
`WindowManager::CreateGLFWWindow()`, to avoid conflict with Windows API
macro.
* Replace lodepng with stb, to also support JPEG file loading (GitLab #41)
* Add shader for celestial rings and load it in lab1 (GitLab #51)
* AppVeyor: switch from VS 2019 Preview to VS 2019
* README: Add tinyfiledialogs to dependencies
* (HEAD -> 2019_updates) README: Sort the list of dependencies
24 changes: 24 additions & 0 deletions CMake/InstallSTB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set (stb_SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/stb-source)

if (NOT EXISTS ${stb_SOURCE_DIR})
message (STATUS "Cloning stb…")
execute_process (
COMMAND ${GIT_EXECUTABLE} clone --depth=1
https://github.com/nothings/stb
${stb_SOURCE_DIR}
OUTPUT_QUIET
ERROR_VARIABLE stderr
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies
)
if (result)
message (FATAL_ERROR "Failed to clone stb: ${result}\n"
"Error output: ${stderr}")
endif ()
endif ()

add_library( stb::stb INTERFACE IMPORTED)
set_target_properties(stb::stb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${stb_SOURCE_DIR}"
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c"
)
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif ()
# Set the project name, versions and languages used.
project (
CG_Labs
VERSION 0.1
VERSION 2019.1
LANGUAGES CXX C
)

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

# stb is used for loading in image files.
include (CMake/InstallSTB.cmake)

# Resources are found in an external archive
include (CMake/RetrieveResourceArchive.cmake)

Expand Down Expand Up @@ -124,7 +127,7 @@ function (luggcgl_new_assignment assignment_name sources common_sources)

add_dependencies (${assignment_name} bonobo)

target_link_libraries (${assignment_name} bonobo imgui::imgui glm tinyfiledialogs::tinyfiledialogs)
target_link_libraries (${assignment_name} bonobo imgui::imgui glm stb::stb tinyfiledialogs::tinyfiledialogs)

install (TARGETS ${assignment_name} DESTINATION bin)
endfunction ()
Expand All @@ -145,7 +148,6 @@ endfunction ()

# Define groups of files for IDEs
set (PATH_SEP \\)
source_group (Source\ Files${PATH_SEP}External${PATH_SEP}lodepng FILES ${PROJECT_SOURCE_DIR}/src/lodepng.cpp ${PROJECT_SOURCE_DIR}/src/external/lodepng.h)
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)
source_group (Source\ Files${PATH_SEP}External${PATH_SEP}GL3W FILES ${PROJECT_SOURCE_DIR}/src/external/gl3w.cpp)

Expand Down
18 changes: 10 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ Dependencies

CG_Labs uses the following dependencies:

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

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

Expand Down Expand Up @@ -122,7 +124,6 @@ Licence
=======

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

.. _Lund University: http://www.lu.se/
Expand All @@ -135,7 +136,8 @@ Licence
.. _GLM: http://glm.g-truc.net/
.. _Dear ImGui: https://github.com/ocornut/imgui
.. _assimp: https://github.com/assimp/assimp
.. _lodepng: http://lodev.org/lodepng/
.. _stb: https://github.com/nothings/stb
.. _tinyfiledialogs: https://sourceforge.net/projects/tinyfiledialogs/
.. _cmake-generators(7): https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html
.. _Dear ImGui’s licence: Dear_ImGui_LICENCE
.. _this ZIP file: http://fileadmin.cs.lth.se/cs/Education/EDA221/assignments/EDA221_resources.zip
Expand Down
30 changes: 30 additions & 0 deletions shaders/EDAF80/celestial_ring.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#version 410

uniform sampler2D diffuse_texture;
uniform sampler2D opacity_texture;
uniform int has_diffuse_texture;
uniform int has_opacity_texture;

in VS_OUT {
vec2 texcoord;
} fs_in;

out vec4 frag_color;

void main()
{
float alpha = 1.0f;
if (has_opacity_texture != 0) {
alpha = texture(opacity_texture,
vec2(1.0f - fs_in.texcoord.x, fs_in.texcoord.y)).r;
if (alpha == 0.0f)
discard;
}

if (has_diffuse_texture != 0)
frag_color = texture(diffuse_texture, fs_in.texcoord);
else
frag_color = vec4(1.0);

frag_color *= alpha;
}
19 changes: 19 additions & 0 deletions shaders/EDAF80/celestial_ring.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 410

layout (location = 0) in vec3 vertex;
layout (location = 2) in vec3 texcoord;

uniform mat4 vertex_model_to_world;
uniform mat4 vertex_world_to_clip;

out VS_OUT {
vec2 texcoord;
} vs_out;


void main()
{
vs_out.texcoord = vec2(texcoord.x, texcoord.y);

gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(vertex, 1.0);
}
56 changes: 30 additions & 26 deletions src/EDAF80/assignment1.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "config.hpp"
#include "parametric_shapes.hpp"
#include "core/Bonobo.h"
#include "core/FPSCamera.h"
#include "core/helpers.hpp"
#include "core/Log.h"
#include "core/LogView.h"
#include "core/Misc.h"
#include "core/node.hpp"
#include "core/ShaderProgramManager.hpp"
#include "core/WindowManager.hpp"

#include <imgui.h>
#include <external/imgui_impl_glfw_gl3.h>
Expand All @@ -19,10 +18,9 @@
int main()
{
//
// Set up the logging system
// Set up the framework
//
Log::Init();
Log::View::Init();
Bonobo framework;

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

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

Log::View::Destroy();
Log::Destroy();

return EXIT_FAILURE;
}

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

Log::View::Destroy();
Log::Destroy();

return EXIT_FAILURE;
}
bonobo::mesh_data const& sphere = objects.front();
Expand All @@ -69,12 +61,26 @@ int main()
// Create the shader program
//
ShaderProgramManager program_manager;
GLuint shader = 0u;
program_manager.CreateAndRegisterProgram({ { ShaderType::vertex, "EDAF80/default.vert" },
GLuint celestial_body_shader = 0u;
program_manager.CreateAndRegisterProgram("Celestial Body",
{ { ShaderType::vertex, "EDAF80/default.vert" },
{ ShaderType::fragment, "EDAF80/default.frag" } },
shader);
if (shader == 0u) {
LogError("Failed to generate the shader program: exiting.");
celestial_body_shader);
if (celestial_body_shader == 0u) {
LogError("Failed to generate the “Celestial Body” shader program: exiting.");

Log::View::Destroy();
Log::Destroy();

return EXIT_FAILURE;
}
GLuint celestial_ring_shader = 0u;
program_manager.CreateAndRegisterProgram("Celestial Ring",
{ { ShaderType::vertex, "EDAF80/celestial_ring.vert" },
{ ShaderType::fragment, "EDAF80/celestial_ring.frag" } },
celestial_ring_shader);
if (celestial_ring_shader == 0u) {
LogError("Failed to generate the “Celestial Ring” shader program: exiting.");

Log::View::Destroy();
Log::Destroy();
Expand All @@ -88,6 +94,8 @@ int main()
//
Node sun_node;
sun_node.set_geometry(sphere);
sun_node.set_program(&celestial_body_shader, [](GLuint /*program*/){});
TRSTransformf& sun_transform_reference = sun_node.get_transform();
GLuint const sun_texture = bonobo::loadTexture2D("sunmap.png");
sun_node.add_texture("diffuse_texture", sun_texture, GL_TEXTURE_2D);
float const sun_spin_speed = glm::two_pi<float>() / 6.0f; // Full rotation in six seconds
Expand Down Expand Up @@ -168,7 +176,7 @@ int main()
//
// Update the transforms
//
sun_node.rotate_y(sun_spin_speed * delta_time);
sun_transform_reference.RotateY(sun_spin_speed * delta_time);


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


//
Expand All @@ -198,9 +206,5 @@ int main()

glDeleteTextures(1, &sun_texture);


Log::View::Destroy();
Log::Destroy();

return EXIT_SUCCESS;
}
Loading

0 comments on commit 1166702

Please sign in to comment.