Skip to content

Commit

Permalink
Merge branch 'fixing-span-usage' into 'master'
Browse files Browse the repository at this point in the history
Reducing the number of copies of data

See merge request graphics-interaction-visualization/givr!16
  • Loading branch information
lakinwecker committed May 30, 2019
2 parents 1215838 + 2171569 commit 4bac5bb
Show file tree
Hide file tree
Showing 541 changed files with 145,095 additions and 1,000 deletions.
13 changes: 0 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ set(GIVR_GLAD_INCLUDE_DIR "" CACHE FILEPATH "Path to glad includes")

set(DEFINITIONS -D_USE_MATH_DEFINES=1 GLM_FORCE_CXX14=1)

if(NOT GLM_FOUND)
find_package(GLM REQUIRED)
endif()

find_file(GIVR_GLAD_H "glad.h" ${GIVR_GLAD_INCLUDE_DIR}/glad)
if(NOT GIVR_GLAD_H)
message(SEND_ERROR "Can't find glad/glad.h in ${GIVR_GLAD_INCLUDE_DIR}")
endif()

include_directories(${GIVR_GLAD_INCLUDE_DIR} src)
file(GLOB SOURCES src/* src/givr/* src/givr/gl/* src/givr/styles/* src/givr/geometry/* src/givr/camera/*)

add_library(givr ${SOURCES})
target_compile_definitions(givr PRIVATE ${DEFINITIONS})
target_link_libraries(givr glm::glm)

55 changes: 55 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required (VERSION 3.5.1) # Not sure what the minimum is required
project (givr_example CXX C)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Use modern C++
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)

include_directories("${PROJECT_BINARY_DIR}" libs src ../src)
add_subdirectory(.. givr)

set(DEFINITIONS _USE_MATH_DEFINES=1 GLM_FORCE_CXX14=1)

if(UNIX)
# setup warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type")

# add extra checks for developer or debug builds
if(CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS")
endif()
endif()

find_package(OpenGL REQUIRED)
set(LIBRARIES ${LIBRARIES} ${OPENGL_gl_LIBRARY})

# GLFW
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(libs/glfw)
set(LIBRARIES ${LIBRARIES} glfw)

file(GLOB sources src/*.cpp src/*.h libs/*.h libs/*.cpp libs/*.c)
set(INCLUDES ${INCLUDES} src)

file(GLOB_RECURSE models RELATIVE ${CMAKE_SOURCE_DIR} models/*)
foreach(file ${models})
configure_file(${file} ${file} COPYONLY)
endforeach(file)

if (UNIX)
set(LIBRARIES ${LIBRARIES} dl)
endif()
file( GLOB APP_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} bin-src/*.cpp )
foreach(example_source ${APP_SOURCES} )
string( REPLACE ".cpp" "" example ${example_source} )
string( REPLACE "bin-src/" "" example ${example} )
add_executable(${example} ${sources} ${example_source})
target_link_libraries(${example} ${LIBRARIES} givr)
target_include_directories(${example} PRIVATE ${INCLUDES})
target_compile_definitions(${example} PRIVATE ${DEFINITIONS})
endforeach( example_source ${APP_SOURCES} )
173 changes: 173 additions & 0 deletions examples/bin-src/kitchen-sink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#include "givr.h"
#include <glm/gtc/matrix_transform.hpp>
#include "io.h"
#include "turntable_controls.h"

using namespace glm;
using namespace givr;
using namespace givr::style;
using namespace givr::geometry;
using namespace givr::camera;

int main(void)
{
io::GLFWContext windows;
auto window =
windows.create(io::Window::dimensions{640, 480}, "Simple example");
// Note this has to be called after the window creation.
window.enableVsync(true);

auto view = View(TurnTable(), Perspective());
TurnTableControls controls(window, view.camera);

auto phongStyle = Phong(
LightPosition(0.0, 0.0, 100.0),
Colour(1.0, 1.0, 0.1529)
);
auto instancedSpheres = createInstancedRenderable(Sphere(), phongStyle);
auto sphere = createRenderable(Sphere(), phongStyle);
auto palmTree = Mesh(Filename("./models/Palm_Tree.obj"));
auto instancedTrees = createInstancedRenderable(palmTree, phongStyle);
auto tree = createRenderable(palmTree, phongStyle);

auto noshading = NoShading(Colour(1.0, 0.0, 0.0));
auto flatSphere = createRenderable(Sphere(), noshading);
auto instancedFlatSpheres = createInstancedRenderable(Sphere(), noshading);
auto polyline = PolyLine<PrimitiveType::LINE_LOOP>(
Point(-10.f, -10.f, 0.f),
Point(10.f, -10.f, 0.f),
Point(10.f, 10.f, 0.f),
Point(-10.f, 10.f, 0.f),
Point(-10.f, -10.f, 0.)
);
auto lineStyle = GL_Line(Width(15.), Colour(0.0, 1.0, 0.0));
auto polylines = createRenderable(polyline, lineStyle);
auto instancedPolylines = createInstancedRenderable(polyline, lineStyle);

auto line = Line(
Point1(-15.0, -15.0, 0.0),
Point2(15.0, 15.0, 0.0)
);
auto lines = createRenderable(line, lineStyle);

auto triangle = Triangle(
Point1(0.0, 15.0, -10.0),
Point2(-15.0, -15.0, -10.0),
Point3(15.0, -15.0, -10.0)
);
auto triangles = createRenderable(triangle, phongStyle);

auto multiLine = MultiLine(
Line(Point1(-20.0, -20.0, 0.0), Point2(-20.0, -10.0, 0.0)),
Line(Point1(-10.0, -10.0, 0.0), Point2(-10.0, 0.0, 0.0)),
Line(Point1(0.0, 0.0, 0.0), Point2(0.0, 10.0, 0.0)),
Line(Point1(10.0, 10.0, 0.0), Point2(10.0, 20.0, 0.0))
);

auto multilines = createRenderable(multiLine, lineStyle);

auto cylinder = Cylinder(
Point1(-15.0, 15.0, 0.f),
Point2(-15.0, -15.0, 0.f)
);
auto cylinders = createRenderable(cylinder, phongStyle);

glClearColor(1.f, 1.f, 1.f, 1.f);

float u = 0.0;
float v = 0.0;

window.run([&](float /*frameTime*/) {
view.projection.updateAspectRatio(window.width(), window.height());

mat4f m = translate(mat4f{1.f}, vec3f{0., 5.0, 0.});
addInstance(instancedSpheres, m);
draw(instancedSpheres, view);

float x = 40.0 * cos(u*0.1);
float y = 40.0 * sin(u*0.1);
phongStyle.set(LightPosition(x, y, 2.0));
updateRenderable(Sphere(), phongStyle, sphere);
updateRenderable(Sphere(), phongStyle, instancedSpheres);
updateRenderable(palmTree, phongStyle, tree);
updateRenderable(palmTree, phongStyle, instancedTrees);

x = 10.0 * cos(u);
y = 10.0 * sin(u);
u += 0.05;
m = translate(mat4f{1.f}, vec3f{x, y, 0.});
draw(sphere, view, m);

x = 3.0 * cos(v) + x;
y = 3.0 * sin(v) + y;
v += 0.1;
m = translate(mat4f{1.f}, vec3f{x, y, 0.});
draw(sphere, view, m);


m = translate(mat4f{1.f}, vec3f{-5., -5.0, -5.});
addInstance(instancedSpheres, m);
draw(instancedSpheres, view);

float angle = 365*sin(u*.001);
x = 24.0 * cos(u*0.1);
y = 24.0 * sin(u*0.1);
u += 0.05;
m = rotate(scale(translate(mat4f{1.f}, vec3f{x, y, 0.}), vec3f{4.f, 4.f, 4.f}), angle, vec3f{1.0f, 1.0f, 0.2f});
draw(tree, view, m);

x = 8.0 * cos(v*0.5) + x;
y = 8.0 * sin(v*0.5) + y;
v += 0.1;
m = translate(mat4f{1.f}, vec3f{x, y, 0.});
draw(tree, view, m);

float r = 0.5 + (0.5 * cos(u*0.3));
float g = 0.5 + (0.5 * sin(u*0.3));
noshading.set(Colour(r, g, 0.0));
updateRenderable(Sphere(), noshading, flatSphere);
updateRenderable(Sphere(), noshading, instancedFlatSpheres);

m = scale(mat4{1.f}, vec3f{4.f, 4.f, 4.f});
m = translate(m, vec3f{0.f, -5.0, 0.});
addInstance(instancedFlatSpheres, m);
draw(instancedFlatSpheres, view);

m = translate(m, vec3f{0.f, 5.0, 0.});
draw(flatSphere, view, m);

lineStyle.set(Width(15.0 * sin(u)));
updateRenderable(polyline, lineStyle, polylines);
updateRenderable(polyline, lineStyle, instancedPolylines);
draw(polylines, view);

m = rotate(
translate(mat4f{1.f}, vec3f{15.0, -15.0, 0.}),
angle,
vec3f{0.f, 0.f, 1.f}
);
addInstance(instancedPolylines, m);
draw(instancedPolylines, view);

m = rotate(
translate(mat4f{1.f}, vec3f{-15.0, 15.0, 0.}),
angle,
vec3f{0.f, 0.f, 1.f}
);
addInstance(instancedPolylines, m);
draw(instancedPolylines, view);

m = rotate(mat4f{1.f}, angle, vec3f{0.f, 0.f, 1.f});
draw(lines, view, m);

m = rotate(mat4f{1.f}, angle, vec3f{1.f, 0.f, 0.f});
draw(triangles, view, m);

m = rotate(mat4f{1.f}, angle, vec3f{0.f, 0.f, 1.f});
draw(multilines, view, m);

m = rotate(mat4f{1.f}, angle, vec3f{0.f, 0.f, 1.f});
draw(cylinders, view, m);
});
exit(EXIT_SUCCESS);
}
54 changes: 54 additions & 0 deletions examples/bin-src/linetransformations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "givr.h"
#include <glm/gtc/matrix_transform.hpp>
#include "io.h"
#include "turntable_controls.h"

using namespace glm;
using namespace givr;
using namespace givr::style;
using namespace givr::geometry;
using namespace givr::camera;

int main(void)
{
io::GLFWContext windows;
auto window =
windows.create(io::Window::dimensions{640, 480}, "Simple example");
// Note this has to be called after the window creation.
window.enableVsync(true);

auto view = View(TurnTable(), Perspective());
TurnTableControls controls(window, view.camera);

auto lineStyle = GL_Line(Width(15.), Colour(1.0, 0.0, 0.0));
auto line = Line(
Point1(-1.0, 0.0, 0.0),
Point2(1.0, 0.0, 0.0)
);
auto lines = createRenderable(line, lineStyle);

glClearColor(1.f, 1.f, 1.f, 1.f);

float u = 0.0;

window.run([&](float /*frameTime*/) {
view.projection.updateAspectRatio(window.width(), window.height());

auto m = mat4f{1.0f};
m[0][0] = m[1][1] = m[2][2] = 10.0f*std::sin(u);
draw(lines, view, m);

float angle = 365*sin(u*0.001);
m = rotate(m, angle, vec3f{0.f, 0.f, 1.f});
draw(lines, view, m);

float x = 10.0 * cos(u*0.001);
float y = 10.0 * sin(u*0.001);
m = translate(mat4f{1.0}, vec3f{x, y, 0.});
draw(lines, view, m);

u += 0.1;

});
exit(EXIT_SUCCESS);
}

0 comments on commit 4bac5bb

Please sign in to comment.