Skip to content

Instantly share code, notes, and snippets.

when isMainModule:
import strutils
import common
import vector2
import vector3
import euler
import quaternion
import math3
import math
type
Array32Part{.unchecked.} = array[0..0, float32]
Buffer32 = ref object
samples: int
bytes: int
data: ptr Array32Part
proc AllocBuffer32(samples : int): Buffer32 =
let bytes = samples * (sizeof(float32))
Buffer32(samples: samples, bytes : bytes, data: cast[ptr Array32Part](alloc0(bytes)))
@triplefox
triplefox / bmp32.nim
Created February 10, 2015 11:25
BMP32 writer
import endians
import sdl2
import sdl2.image
discard IMG_Init
proc loadImage*(filename:string):PSurface=
var suce = IMG_Load(cstring(filename))
@triplefox
triplefox / gist:0edbfd1a14af0f5513f1
Last active August 29, 2015 14:14
Version 3 - the "most correct" iteration
class Node
{
public var ci : Array<Int>; /* channel in */
public var co : Array<Int>; /* channel out */
public var i : Int; /* id */
public var b : Int; /* behavior */
public var a : Bool; /* alive */
public function new(i,a) { ci = []; co = []; this.i = i; this.b = -1; this.a = a; }
}
type
GLFloatBufferPart{.unchecked.} = array[0..0, GLfloat]
GLFloatBuffer* = ref tuple
data : ptr GLFloatBufferPart
samples : int
bytes : int
# i want to expand this to all the GL numeric types through a generic:
@triplefox
triplefox / gist:b64eb859b4152dc5ae5c
Created January 16, 2015 11:53
Data types for 2d sprite packing tool
type
DataEntry* = object
k:string # key
v:int # value
Rect* = object
x:int
y:int
w:int # width
h:int # height
d:seq[DataEntry] # metadata
# Generate and playback a sine tone
import sdl2
import sdl2/audio
import math
# Audio settings requested:
const RQBufferSizeInSamples = 4096
const RQBytesPerSample = 2 # 16 bit PCM
const RQBufferSizeInBytes = RQBufferSizeInSamples * RQBytesPerSample
type Uniforms = object
faefar:GLint # fade factor
tee:array[0..1,GLint] # textures
type Attributes = object
pon:GLint # position
type Resources = object
vexbur, eltbur:GLuint # vertex, element buffers
tee:array[0..1,GLuint] # textures
vexshr, frtshr:GLuint # vertex, element shaders
prm:GLuint # program
# Generate and playback a sine tone
import sdl2
import sdl2/audio
import math
# Audio settings:
const Channels = 1
const RQSizeInSamples = 4096 * Channels
@triplefox
triplefox / ExampleEventSys.hx
Created December 20, 2014 11:55
Example event system
class Eventsys
{
public var entities = new Map<Int, IEntity>();
public function new(){}
/* raw spawning tools. instantiate and assign parameters to entities with your own configuration mechanism. */
public function spawn(e : IEntity, id : Int) { if (entities.exists(id)) { throw "overlapping entity id"; } e.id = id; entities.set(id, e); }
public function despawn(e : IEntity) { entities.remove(e.id); }