Skip to content

Instantly share code, notes, and snippets.

View mortennobel's full-sized avatar

Morten Nobel-Jørgensen mortennobel

View GitHub Profile
#include <chrono>
#include <iostream>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#ifdef _WIN32
#include <windows.h>
#endif
@mortennobel
mortennobel / BussIKMain.cpp
Created March 20, 2018 10:05
BussIK using SimpleRenderEngine
// Naive port of https://github.com/CreativeInquiry/ofxBussIK
#include <iostream>
#include "sre/Texture.hpp"
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"
#include "LinearR3.h"
#include "Tree.h"
#include "Jacobian.h"
#include <iostream>
#include <string>
#include <memory>
struct String {
std::string s;
String(std::string s)
:s(s) {
std::cout << "Constructor " << s << std::endl;
}
while (running){
frame(deltaTime);
auto tick = Clock::now();
deltaTime = std::chrono::duration_cast<FpSeconds>(tick - lastTick).count();
// todo fix busy wait
// https://forum.lazarus.freepascal.org/index.php?topic=35689.0
while (deltaTime < timePerFrame){
SDL_Delay((Uint32) ((timePerFrame - deltaTime) / 1000));
tick = Clock::now();
deltaTime = std::chrono::duration_cast<FpSeconds>(tick - lastTick).count();
@mortennobel
mortennobel / SingleFileOpenGLTex.cpp
Last active January 25, 2024 10:03
Single file OpenGL 3.3 / WebGL (using Emscripten) example with texture (SDL2 / SDL_Image 2)
//
// Compile for emscripten using
// emcc -Iinclude SingleFileOpenGLTex.cpp \
-O2 -std=c++14 -s TOTAL_MEMORY=33554432 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' --preload-file examples/data -s USE_SDL=2 -o html/SingleFileOpenGLTex.html
// where the following images must be located in a subfolder
// - examples/data/test.png
// - examples/data/cartman.png
// - examples/data/cube-negx.png
// - examples/data/cube-negz.png
//
@mortennobel
mortennobel / geometryshader.cpp
Created March 14, 2017 13:32
Single file geometryshader
#include "SDL.h"
// OSX only - change on other platforms
#include <OpenGL/gl3.h>
#include <stdlib.h> //rand()
#include <iostream>
#include <string>
static bool quitting = false;
static SDL_Window *window = NULL;
@mortennobel
mortennobel / Handle.cpp
Created November 21, 2016 19:31
EntitySystem using handles
//
// Created by Morten Nobel-Jørgensen on 20/11/2016.
//
#include "Handle.hpp"
@mortennobel
mortennobel / SingleFileOpenGLExample.cpp
Last active November 7, 2016 11:46
OpenGL 3.x example in a single file (SDL2.x)
#include "SDL.h"
// OSX only - change on other platforms
#include <OpenGL/gl3.h>
#include <stdlib.h> //rand()
#include <iostream>
#include <string>
static bool quitting = false;
static SDL_Window *window = NULL;
using UnityEngine;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
public class HelloSocketWorld : MonoBehaviour {
public string history;
public string txt;
@mortennobel
mortennobel / encode_image.sh
Created April 24, 2016 18:32
Encode png images as movie
# Loosely based on http://superuser.com/a/533706
ffmpeg -framerate 10 -i shot\ %04d.png -s:v 1280x720 -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p smart-avenue-1.mp4