Skip to content

Instantly share code, notes, and snippets.

@scan
Created November 2, 2012 22:41
Show Gist options
  • Save scan/4004808 to your computer and use it in GitHub Desktop.
Save scan/4004808 to your computer and use it in GitHub Desktop.
vboOfList :: Int -> [Float] -> IO BufferObject
vboOfList size elems =
let ptrsize = toEnum $ size * 4
arrayType = ElementArrayBuffer
in do
[array] <- genObjectNames 1
bindBuffer arrayType $= Just array
arr <- newListArray (0, size - 1) elems
withStorableArray arr (\ptr -> bufferData arrayType $= (ptrsize, ptr, StaticDraw))
bindBuffer ArrayBuffer $= Nothing
reportErrors
return array
displayVbo buff size = do
let stride = toEnum sizeOfVertexInfo
vxDesc = VertexArrayDescriptor 3 Float stride $ offset 0
colors = VertexArrayDescriptor 4 Float stride $ offset 12
texCoo = VertexArrayDescriptor 2 Float stride $ offset (12 + 16)
filt = VertexArrayDescriptor 4 Float stride $ offset (12 + 16 + 8)
bindBuffer ArrayBuffer $= Just buff
arrayPointer VertexArray $= vxDesc
arrayPointer ColorArray $= colors
arrayPointer TextureCoordArray $= texCoo
arrayPointer SecondaryColorArray $= filt
drawArrays Quads 0 size
bindBuffer ArrayBuffer $= Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment