Skip to content

Instantly share code, notes, and snippets.

View mortennobel's full-sized avatar

Morten Nobel-Jørgensen mortennobel

View GitHub Profile
@mortennobel
mortennobel / floatingpoint.h
Last active August 29, 2015 14:00
almostEqualFloatingpoint
// from https://code.google.com/p/googletest/source/browse/trunk/include/gtest/internal/gtest-internal.h
#pragma once
#include <ctype.h>
#include <float.h>
#include <string.h>
#include <iomanip>
#include <limits>
#include <set>
@mortennobel
mortennobel / ascii-2d.cpp
Last active August 29, 2015 13:56
ASCII visualization (used for debugging 2d scalar fields)
#include <string>
#include <array>
#include <algorithm>
#include <functional>
using namespace std;
// assumes that values returned by data is normalized between 0.0 and 1.0
string get_grayscale_image(int width, int height, function<float(int,int)> data){
const int size = 10;
@mortennobel
mortennobel / drand48.c
Created January 28, 2014 10:24
drand48() and srand48(long) on windows. (based on Freebsd: http://fxr.watson.org/fxr/ident?v=FREEBSD-LIBC;im=bigexcerpts;i=_dorand48 )
#define RAND48_SEED_0 (0x330e)
#define RAND48_SEED_1 (0xabcd)
#define RAND48_SEED_2 (0x1234)
#define RAND48_MULT_0 (0xe66d)
#define RAND48_MULT_1 (0xdeec)
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
unsigned short _rand48_seed[3] = {
@mortennobel
mortennobel / plasma.c
Created October 17, 2013 06:57
plasma effect (from Unity's RenderingPluginExample42)
// Simple oldskool "plasma effect", a bunch of combined sine waves
// input x,y (uv-coordinates), t (time)
int vv = int(
(127.0f + (127.0f * sinf(x/7.0f+t))) +
(127.0f + (127.0f * sinf(y/5.0f-t))) +
(127.0f + (127.0f * sinf((x+y)/6.0f-t))) +
(127.0f + (127.0f * sinf(sqrtf(float(x*x + y*y))/4.0f-t)))
) / 4;
@mortennobel
mortennobel / Event.h
Last active July 3, 2018 14:46
C++11 Observer Version 2
//
// Event.h
//
// Created by Morten Nobel-Jørgensen on 8/18/13.
// Copyright (c) 2013 morten. All rights reserved.
// Open Source under New BSD License (http://opensource.org/licenses/BSD-3-Clause)
#pragma once
#include <iostream>
@mortennobel
mortennobel / cpp11shim.h
Created July 22, 2013 13:54
c++11 shim (allows you to use a C++11 compiler with the stdlibc++ without C++11 support ... useful when depending on old libraries).
//
// cpp11shim.h
//
// Created by Morten Nobel-Jørgensen on 7/19/13.
// Copyright (c) 2013 Morten Nobel-Joergensen. All rights reserved.
//
#ifndef __CPP11_SHIM__
#define __CPP11_SHIM__
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-08T13:26:39
#
#-------------------------------------------------
QT += core gui widgets opengl network
TARGET = QtImageCompressionTest
CONFIG += console
#include <functional>
#include <deque>
#include <mutex>
// Reuseable blocking queue
template <typename T> class BlockingQueue {
std::deque<T> q;
std::mutex m;
std::condition_variable cv;
public:
@mortennobel
mortennobel / observer.cpp
Last active December 16, 2015 03:39
Observer pattern in C++11
//
// main.cpp
// Observer pattern in C++11
//
// Created by Morten Nobel-Jørgensen on 9/21/12.
// Copyright (c) 2012 Morten Nobel-Joergensen. All rights reserved.
//
#include <iostream>
@mortennobel
mortennobel / libPNGOpenGL.cpp
Last active April 29, 2020 09:12
Updated to libpng 1.5.15
#ifdef _WIN32
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <png.h>
#include <iostream>