Skip to content

Instantly share code, notes, and snippets.

View christophercrouzet's full-sized avatar

Christopher Crouzet christophercrouzet

View GitHub Profile
@christophercrouzet
christophercrouzet / tests.cmake
Last active August 29, 2015 14:04
Heper to add tests in CMake
include(CMakeParseArguments)
function(create_test target_name)
set(options)
set(single_value_args FILE OUTPUT_DIR NAME)
set(multi_value_args LINK_LIBS)
cmake_parse_arguments(
create_test
"${options}"
@christophercrouzet
christophercrouzet / glew.cmake
Created August 5, 2014 12:58
Helper to build GLEW statically with CMake
# Tested only on Mac OS X Mavericks with GLEW v1.10.0.
function(build_glew root_dir)
set(glew_lib GLEW)
if (APPLE)
set(glew_platform_libs "-framework AGL" "-framework OpenGL")
elseif (WIN32)
set(glew_lib glew32)
set(glew_platform_libs opengl32 glu32)
else()
@christophercrouzet
christophercrouzet / shaders.cmake
Created August 5, 2014 13:00
Command to format GLSL shaders with CMake for inclusion in C++
separate_arguments(FILES)
foreach (file ${FILES})
if (LOAD_SHADERS_DYNAMICALLY)
file(
COPY ${SOURCE_DIR}/${file}
DESTINATION ${DESTINATION_DIR}
)
else()
set(filename ${SOURCE_DIR}/${file})
@christophercrouzet
christophercrouzet / getmodulenamefrompath.py
Created August 5, 2014 13:18
Retrieves a module name from a path
import inspect
import os
def get_module_name_from_path(path):
if not os.path.exists(path):
raise ValueError("The path '%s' is not a valid path." % path)
path = os.path.abspath(path)
full_names = []
@christophercrouzet
christophercrouzet / gist:1fea72d0d88e5a0dca16
Created August 16, 2014 03:03
OpenGL projection matrix to fit the content to the window while preserving the aspect ratio
int shorterSide = std::min(width, height);
GLfloat marginX = 1.0f + GLfloat(width - shorterSide) / (GLfloat)shorterSide;
GLfloat marginY = 1.0f + GLfloat(height - shorterSide) / (GLfloat)shorterSide;
glm::mat4 projection = glm::ortho(-marginX, marginX, -marginY, marginY);
@christophercrouzet
christophercrouzet / gist:49dcd547b766030ddd2d
Last active August 29, 2015 14:09
Uniform distribution of floating-point values in C++.
#include <algorithm>
#include <array>
#include <cmath>
#include <random>
#include <iomanip>
#include <ios>
#include <iostream>
@christophercrouzet
christophercrouzet / distance.h
Last active April 16, 2024 13:02
Compute the distance in ulps between floating-point numbers in C++11.
#ifndef DISTANCE_H
#define DISTANCE_H
#include <algorithm>
#include <cassert>
#include <cmath>
#include <limits>
#include "floatingpointtraits.h"
@christophercrouzet
christophercrouzet / gist:b3e4567c4fd3a9fe9b8c
Last active August 29, 2015 14:11
Check if a function that can be called with a specific set of arguments exists.
#include <iomanip>
#include <iostream>
#include <string>
#include <type_traits>
#include <utility>
template<typename T>
struct Functions;
@christophercrouzet
christophercrouzet / multidimensionalarray.h
Last active November 30, 2018 12:35
Nested initializer lists for multidimensional arrays in C++11.
#ifndef MULTIDIMENSIONALARRAY_H
#define MULTIDIMENSIONALARRAY_H
#include <array>
#include <cstddef>
#include <type_traits>
// https://github.com/christophercrouzet/m3ta
#include <m3ta/nestedinitializerlists>
#include <m3ta/pass>
@christophercrouzet
christophercrouzet / strides.h
Last active August 29, 2015 14:17
Compute the strides of a n-dimensional array either at compile or run time.
#ifndef STRIDES_H
#define STRIDES_H
#include <cstddef>
#include <m3ta/concatenateintegersequences>
#include <m3ta/integersequence>
#include <m3ta/reverseintegersequence>