Skip to content

Instantly share code, notes, and snippets.

View SimonDanisch's full-sized avatar
🏠
Working from home

Simon SimonDanisch

🏠
Working from home
View GitHub Profile
using GLUT, ModernGL
function aglGetProcAddress(glFuncName::String)
tmp = "_"*glFuncName
if ccall(:NSIsSymbolNameDefined, Cint, (Ptr{Uint8},), tmp) == 0
return convert(Ptr{Void}, 0)
else
symbol = ccall(:NSLookupAndBindSymbol, Ptr{Void}, (Ptr{Uint8},), tmp)
return ccall(:NSAddressOfSymbol, Ptr{Void}, (Ptr{Void},), symbol)
end
#Find the correct type of the data
imgType = eltype(data)
if imgType == Uint8
glImgType = GL_UNSIGNED_BYTE
elseif imgType == Float32
glImgType = GL_FLOAT
elseif imgType == Int8
glImgType = GL_BYTE
else
error("Type: $(imgType) not supported")
abstract Enum
macro GenEnums(list)
const result = {}
enumlist = Dict{Symbol, Dict{Int, Symbol}}()
tmp = list.args[2].args
tmp2 = tmp[2].args
enumdict1 = Dict{Int, Symbol}()
for elem in tmp2
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
static void error_callback(int error, const char* description)
{
fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
mesh =
[
:indexes => GLBuffer{GLuint}(convert(Ptr{GLuint}, pointer(indices)), sizeof(indices), 1, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW),
:vertex => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(xyz)), sizeof(xyz), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:normal => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(normals)), sizeof(normals), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:tangent => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(tangents)), sizeof(tangents), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:binormal => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(binormals)), sizeof(binormals), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:view => cam.view,
mesh =
[
:indexes => GLBuffer{GLuint}(convert(Ptr{GLuint}, pointer(indices)), sizeof(indices), 1, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW),
:vertex => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(xyz)), sizeof(xyz), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:normal => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(normals)), sizeof(normals), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:tangent => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(tangents)), sizeof(tangents), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:binormal => GLBuffer{Float32}(convert(Ptr{Float32}, pointer(binormals)), sizeof(binormals), 3,GL_ARRAY_BUFFER, GL_STATIC_DRAW),
:view => cam.view,
function fieldtype(x::Any)
T = typeof(x)
if !isbits(T)
error(T, " is not a bitstype, so it doesn't have the right memory layout")
end
types = T.types
@assert !isempty(types)
ftype = types[1]
if any(t -> t!= ftype, types)
error("field types are not homogenious for: ", T)
function fieldtype(x::Any)
T = typeof(x)
if !isbits(T)
error(T, " is not a bitstype, so it doesn't have the right memory layout")
end
types = T.types
@assert !isempty(types)
ftype = types[1]
if any(t -> t!= ftype, types)
error("field types are not homogenious for: ", T)
function fieldtype(x::Any)
T = typeof(x)
if !isbits(T)
error(T, " is not a bitstype, so it doesn't have the right memory layout")
end
types = T.types
@assert !isempty(types)
ftype = types[1]
if any(t -> t!= ftype, types)
error("field types are not homogenious for: ", T)
function fieldtype(x::Any)
T = typeof(x)
# type checks
if !isbits(T)
error(T, " is not a bitstype, so it doesn't have the right memory layout")
end
types = T.types
@assert !isempty(types) # type must have at least one field
ftype = types[1]
if any(t -> t!= ftype, types)