Skip to content

Instantly share code, notes, and snippets.

@ReneSac
Last active August 29, 2015 13:56
Show Gist options
  • Save ReneSac/56fa1fa99d1551d3ca96 to your computer and use it in GitHub Desktop.
Save ReneSac/56fa1fa99d1551d3ca96 to your computer and use it in GitHub Desktop.
import opengl, glfw/glfw
type
TCoord = enum
x, y, z
TVertex = object
pos: array[TCoord, GLfloat]
normal: array[TCoord, GLfloat]
var
vertices: array[NumVertices, TVertex]
converter toGlVec(a: Array[3, int]) : array[TCoord, GLfloat] =
return [a[x.ord].GlFloat, a[y.ord].GlFloat, a[z.ord].GlFloat]
# Call:
newVertexGroup([0, 0, 1] , [-1, -1, 1] , [1, -1, 1] , [1, 1, 1] , [-1, 1, 1] )
#Works:
proc newVertexGroup(normal: Array[3, int], pos: varargs[Array[3, int]]) =
var curVertex {.global.} = 0
for p in pos:
vertices[curVertex] = TVertex(pos: p, normal: normal)
curVertex.inc
#Fails:
proc newVertexGroup(normal: array[TCoord, GLfloat], pos: varargs[array[TCoord, GLfloat]]) =
var curVertex {.global.} = 0
for p in pos:
vertices[curVertex] = TVertex(pos: p, normal: normal)
curVertex.inc
# Error: type mismatch: got (Array constructor[0..2, int], Array constructor[0..2, int], Array constructor[0..2, int], Array constructor[0..2, int], Array constructor[0..2, int])
#but expected one of:
#N.newVertexGroup(normal: array[TCoord, GLfloat], pos: varargs[array[TCoord, GLfloat]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment