Skip to content

Commit

Permalink
Merge pull request #36 from mortennobel/1.1.1
Browse files Browse the repository at this point in the history
1.1.1
  • Loading branch information
mortennobel authored Jun 4, 2018
2 parents 56c19cc + d8444b4 commit 7dd1e0f
Show file tree
Hide file tree
Showing 334 changed files with 653 additions and 77,459 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "submodules/imgui"]
path = submodules/imgui
url = https://github.com/ocornut/imgui.git
[submodule "submodules/glm"]
path = submodules/glm
url = https://github.com/g-truc/glm.git
[submodule "submodules/picojson"]
path = submodules/picojson
url = https://github.com/kazuho/picojson.git
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ addons:
- libsdl2-image-dev

script:
- CXX=/usr/bin/g++-5 CC=/usr/bin/gcc-5 cmake .
- CXX=/usr/bin/g++-5 CC=/usr/bin/gcc-5 cmake -DUSE_SRE_TEST_AND_UTILS=ON .
- cmake --build . -- -j2
31 changes: 20 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,45 @@ if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
"$ cmake ${CMAKE_CURRENT_SOURCE_DIR}")
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")


find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
include_directories(sre)
include_directories(include)
set(SRE_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})

#########################################################
# FIND OPENGL
#########################################################
IF(APPLE)
INCLUDE_DIRECTORIES ( /System/Library/Frameworks )
list(APPEND SRE_INCLUDE_DIRS /System/Library/Frameworks)
FIND_LIBRARY(OpenGL_LIBRARY OpenGL )
MARK_AS_ADVANCED (OpenGL_LIBRARY)
SET(EXTRA_LIBS ${OpenGL_LIBRARY})
ELSE (APPLE)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
list(APPEND SRE_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
IF(UNIX)
find_package(GLEW REQUIRED)
ELSE(UNIX)
find_package(glew REQUIRED)
ENDIF(UNIX)
include_directories(${GLEW_INCLUDE_DIR})
list(APPEND SRE_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
SET(EXTRA_LIBS ${OPENGL_LIBRARY} ${GLEW_LIBRARY})
ENDIF (APPLE)

find_package(SDL2_IMAGE REQUIRED)
include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
list(APPEND SRE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIRS})

option(USE_OPENVR "Enable OpenVR" OFF)

set(OPENVR_LIB)
IF (USE_OPENVR)
find_package(OpenVR REQUIRED)
include_directories(${OPENVR_INCLUDE_DIRS})
list(APPEND SRE_INCLUDE_DIRS ${OPENVR_INCLUDE_DIRS})
IF(UNIX)
add_definitions(-DSRE_OPENVR)
ELSE(UNIX)
Expand All @@ -66,11 +67,19 @@ IF (USE_OPENVR)
ENDIF(APPLE)
ENDIF(USE_OPENVR)

add_subdirectory(submodules)
set(SRE_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include ${EXTRA_INCLUDE} ${SRE_INCLUDE_DIRS} CACHE PATH "" FORCE)
include_directories(${SRE_INCLUDE})

add_subdirectory(src)
add_subdirectory(examples)
SET(USE_SRE_EXAMPLES ON CACHE BOOL "Enable examples for SRE")
if (USE_SRE_EXAMPLES)
add_subdirectory(examples)
endif(USE_SRE_EXAMPLES)

option(USE_SRE_TEST_AND_UTILS "Enable Tests and Utils for SRE" OFF)
SET(USE_SRE_TEST_AND_UTILS OFF CACHE BOOL "Enable Tests and Utils for SRE")
IF (USE_SRE_TEST_AND_UTILS)
add_subdirectory(test)
add_subdirectory(utils)
ENDIF(USE_SRE_TEST_AND_UTILS)
set(SRE_LIBRARIES SRE ${EXTRA_LIBS} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARIES} ${OPENVR_LIB} CACHE PATH "" FORCE)
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ To keep sre as simple and flexible as possible the following features are not a
* Deferred rendering
* Dynamic particle systems

## Getting started

First clone the library (git clone --recurse-submodules https://git`hub.com/mortennobel/SimpleRenderEngine.git`). You can use of the examples as starting point.

Alternative, use the [SimpleRenderEngineProject](https://github.com/mortennobel/SimpleRenderEngineProject) as starting point, which bundles all/most dependencies for Windows and macOS.

## Examples

Example usage can be found in the examples folder.

[![Matcap](https://mortennobel.github.io/SimpleRenderEngine/examples/07_matcap.png)](https://mortennobel.github.io/SimpleRenderEngine/examples/07_matcap.html)[![Picking](https://mortennobel.github.io/SimpleRenderEngine/examples/09_picking.png)](https://mortennobel.github.io/SimpleRenderEngine/examples/09_picking.html)[![Skybox](https://mortennobel.github.io/SimpleRenderEngine/examples/10_skybox-example.png)](https://mortennobel.github.io/SimpleRenderEngine/examples/10_skybox-example.html)[![Render to texture](https://mortennobel.github.io/SimpleRenderEngine/examples/12_render-to-texture.png)](https://mortennobel.github.io/SimpleRenderEngine/examples/12_render-to-texture.html)[![Cloth_Simulation](https://mortennobel.github.io/SimpleRenderEngine/examples/15_cloth_simulation.png)](https://mortennobel.github.io/SimpleRenderEngine/examples/15_cloth_simulation.html)[![Shadows](https://mortennobel.github.io/SimpleRenderEngine/examples/16_shadows.png)](https://mortennobel.github.io/SimpleRenderEngine/examples/16_shadows.html)


More examples/projects can be found on https://github.com/mortennobel/SimpleRenderEngineProject which also contains
all/most dependencies for Windows and macOS.

## Documentation

API documentation is defined in header files.
Expand Down
1 change: 1 addition & 0 deletions examples/02_spheres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <sre/SDLRenderer.hpp>
Expand Down
2 changes: 1 addition & 1 deletion examples/03_spinning-cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"


#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/04_spinning-primitives-tex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <sre/SDLRenderer.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/05_obj-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/06_custom-mesh-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <sre/SDLRenderer.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/07_matcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/08_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sre/Inspector.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>

Expand Down
1 change: 1 addition & 0 deletions examples/09_picking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <sre/SDLRenderer.hpp>
Expand Down
2 changes: 1 addition & 1 deletion examples/10_skybox-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"


#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
Expand Down
2 changes: 1 addition & 1 deletion examples/11_sprite-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"


#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>

Expand Down
1 change: 1 addition & 0 deletions examples/12_render-to-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <sre/Inspector.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/13_benchmark64k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/14_spinning-primitives-openvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sre/VR.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <sre/SDLRenderer.hpp>
Expand Down
2 changes: 1 addition & 1 deletion examples/15_cloth_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"


#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
Expand Down
1 change: 1 addition & 0 deletions examples/16_shadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
Expand Down
109 changes: 109 additions & 0 deletions examples/17_deferred-shading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <iostream>

#include "sre/Texture.hpp"
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <sre/SDLRenderer.hpp>
#include <sre/impl/GL.hpp>
#include <sre/Inspector.hpp>
#include <sre/ModelImporter.hpp>

using namespace sre;

class Deferred{
public:
Deferred(){
r.init();

mesh = sre::ModelImporter::importObj("examples_data/sponza/", "sponza.obj", materials);

worldLights.setAmbientLight(glm::vec3{0.02f});
lightDirection = glm::normalize(glm::vec3{1,1,1});
worldLights.addLight(Light::create().withDirectionalLight(lightDirection).withColor(Color(1,1,1),7).build());

camera.setPerspectiveProjection(fieldOfViewY,near,far);
camera.lookAt(eye,at,{0,1,0});

r.frameRender = [&](){
render();
};
r.mouseEvent = [&](SDL_Event& event){
if (event.type == SDL_MOUSEMOTION){
float mouseSpeed = 1/50.0f;
rotateY = event.motion.x*mouseSpeed;
rotateX = event.motion.y*mouseSpeed;
glm::vec4 atRel = glm::rotate(rotateY, glm::vec3(0,1,0))*glm::rotate(rotateX, glm::vec3(1,0,0))*glm::vec4(0,0,1,0);
at = eye+glm::vec3(atRel);
camera.lookAt(eye,at,{0,1,0});
}
if (event.button.button == SDL_BUTTON_RIGHT){
showInspector = true;
}
};
r.startEventLoop();
}

void render(){
// render pass - render world with shadow lookup
auto rp = RenderPass::create()
.withCamera(camera)
.withClearColor(true,{0,0,0,1})
.withWorldLights(&worldLights)
.build();

rp.draw(mesh, glm::mat4(1),materials);


static Inspector inspector;
inspector.update();
if (showInspector){
inspector.gui();
}
}
private:
void initFramebufferObject(int width, int height){
positionTexture = Texture::create().withRGBData(nullptr, width, height).withName("position").build();
depthTexture = Texture::create().withDepth(width, height).withName("depth").build();
normalTexture = Texture::create().withRGBData(nullptr, width, height).withName("normal").build();
colorTexture = Texture::create().withRGBAData(nullptr, width, height).withName("color").build();
framebuffer = Framebuffer::create()
.withColorTexture(positionTexture)
.withDepthTexture(depthTexture)
.withColorTexture(normalTexture)
.withColorTexture(colorTexture)
.build();
}
std::shared_ptr<Framebuffer> framebuffer;
std::shared_ptr<Texture> positionTexture;
std::shared_ptr<Texture> depthTexture;
std::shared_ptr<Texture> normalTexture;
std::shared_ptr<Texture> colorTexture;
float fieldOfViewY = 45;
float near = 0.1;
float far = 100;
unsigned int shadowMapSize = 1024;
glm::vec3 eye = {0,1.8,0};
glm::vec3 at = {0,1.8,1};
glm::vec3 lightDirection;
SDLRenderer r;
Camera shadowmapCamera;
Camera camera;
std::vector<std::shared_ptr<Material>> materials;
std::shared_ptr<Mesh> mesh;
float rotateX = 0;
float rotateY = 0;
int texture = 0;
bool showInspector = false;
WorldLights worldLights;
};

int main() {
std::make_unique<Deferred>();
return 0;
}

2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET(scr_files 00_hello-engine 01_hello-engine-raw 02_spheres 03_spinning-cube 04_spinning-primitives-tex 05_obj-viewer 06_custom-mesh-layout 07_matcap 08_gui 09_picking 10_skybox-example 11_sprite-example 12_render-to-texture 13_benchmark64k 14_spinning-primitives-openvr 15_cloth_simulation 16_shadows)
SET(scr_files 00_hello-engine 01_hello-engine-raw 02_spheres 03_spinning-cube 04_spinning-primitives-tex 05_obj-viewer 06_custom-mesh-layout 07_matcap 08_gui 09_picking 10_skybox-example 11_sprite-example 12_render-to-texture 13_benchmark64k 14_spinning-primitives-openvr 15_cloth_simulation 16_shadows 17_deferred-shading)

# Create custom build targets
FOREACH(scr_file ${scr_files})
Expand Down
Loading

0 comments on commit 7dd1e0f

Please sign in to comment.