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 / 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;
@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 / 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;
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();
#include <iostream>
#include <string>
#include <memory>
struct String {
std::string s;
String(std::string s)
:s(s) {
std::cout << "Constructor " << s << std::endl;
}
@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"
@mortennobel
mortennobel / SetPngTransparentColorGUI.java
Created October 14, 2012 17:16
Replace pixels with full transparency with a certain color to fix issues with resampling images
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@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 / GLError.cpp
Last active September 27, 2018 07:14
Simple error check of open gl (write readable error description to cerr stream including file name and line number)
#include "GLError.h"
#include <iostream>
#include <string>
#ifdef WIN32
# include <GL/glew.h>
#elif __APPLE__
# include <OpenGL/gl3.h>
#else
# include <GL3/gl3.h>
@mortennobel
mortennobel / AsciiArtGenerator
Created November 6, 2011 20:55
Create image with ASCII chars ordered by intensity
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.*;
/**
* Create an ASCII letters sorted by intensity. By including the inverse letters
* the number of combinations are increased.
*