Skip to content

Instantly share code, notes, and snippets.

View henriquerichter's full-sized avatar

Henrique Richter henriquerichter

View GitHub Profile
import time
class Benchmark():
def __init__(self, txt):
self.txt = str(txt)
self.start = time.time()
def __enter__(self):
return self
@henriquerichter
henriquerichter / Delegates.cpp
Last active August 21, 2018 00:23
Delegates / Pointer to function C++
// https://stackoverflow.com/questions/9568150/what-is-a-c-delegate
Option 1 : functors:
A function object may be created by implementing operator()
struct Functor
{
// Normal class/struct members
int operator()(double d) // Arbitrary return types and parameter list
{
@henriquerichter
henriquerichter / DLLLoad.cpp
Last active July 29, 2017 18:38
Simple DLL loading example, windows only
#include "DLLLoad.h"
int func1() {
printf("func1\n");
func2();
printf("done\n");
return 132;
}
void func2() {
printf("func2\n"); func3(); }
@henriquerichter
henriquerichter / BigO
Last active July 29, 2017 18:40
BigO
http://bigocheatsheet.com/
https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/
https://en.wikipedia.org/wiki/Big_O_notation#Orders_of_common_functions
@henriquerichter
henriquerichter / MergeSort.cpp
Created July 29, 2017 15:23
Implementation of MergeSort using STL
//http://ysonggit.github.io/2015/01/26/efficient-implementation-of-mergesort-using-stl.html
#include <vector>
#include <iostream>
#include <algorithm>
template<class Iter>
void merge_sort(Iter first, Iter last){
if (last - first > 1) {
Iter middle = first + (last - first) / 2;
@henriquerichter
henriquerichter / window.cpp
Created July 27, 2017 22:55
Simple SDL Window + OpenGL
Window window = Window();
window.openWindow("Main Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h);
################################
#include "Window.h"
#include <glew.h>
Window::Window()
{
glTranslate, glRotate, glScale
Are these hardware accelerated?
No, there are no known GPUs that execute this. The driver computes the matrix on the CPU and uploads it to the GPU.
All the other matrix operations are done on the CPU as well : glPushMatrix, glPopMatrix, glLoadIdentity, glFrustum, glOrtho.
This is the reason why these functions are considered deprecated in GL 3.0. You should have your own math library, build your own matrix, upload your matrix to the shader.
@henriquerichter
henriquerichter / main.cpp
Last active July 24, 2017 19:13
Simple SDL Window
#include <iostream>
#include <SDL.h>
int w = 800;
int h = 600;
SDL_Window *window = NULL;
SDL_Surface *screenSurface = NULL;
void mainLoop();
void initSDL();
cmake_minimum_required(VERSION 3.9.0)
project(proj0)
file(GLOB_RECURSE sources ../src/*.cpp)
file(GLOB_RECURSE sources_test ../src/test/*.cpp)
file(GLOB_RECURSE data ../resources/*)
add_executable(main ${sources} ${data})
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/../bin)