Skip to content

Commit 805206e

Browse files
committed
Minor tweaks to Triangles.hs.
1 parent 6a5374b commit 805206e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

examples/RedBook8/Chapter01/Triangles.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Triangles.hs (adapted from triangles.cpp which is (c) The Red Book Authors.)
33
Copyright (c) Sven Panne 2014 <[email protected]>
44
This file is part of HOpenGL and distributed under a BSD-style license
5-
See the file libraries/GLUT/LICENSE
5+
See the file GLUT/LICENSE
66
77
Our first OpenGL program.
88
-}
@@ -33,11 +33,12 @@ init = do
3333
Vertex2 0.90 0.90 ,
3434
Vertex2 (-0.85) 0.90 ] :: [Vertex2 GLfloat]
3535
numVertices = length vertices
36+
vertexSize = sizeOf (head vertices)
3637

3738
arrayBuffer <- genObjectName
3839
bindBuffer ArrayBuffer $= Just arrayBuffer
3940
withArray vertices $ \ptr -> do
40-
let size = fromIntegral (numVertices * sizeOf (head vertices))
41+
let size = fromIntegral (numVertices * vertexSize)
4142
bufferData ArrayBuffer $= (size, ptr, StaticDraw)
4243

4344
program <- loadShaders [
@@ -48,10 +49,12 @@ init = do
4849
let firstIndex = 0
4950
vPosition = AttribLocation 0
5051
vertexAttribPointer vPosition $=
51-
(ToFloat, VertexArrayDescriptor 2 Float 0 (bufferOffset firstIndex))
52+
(ToFloat,
53+
VertexArrayDescriptor 2 Float 0 (bufferOffset (firstIndex * vertexSize)))
5254
vertexAttribArray vPosition $= Enabled
5355

54-
return $ Descriptor triangles firstIndex (fromIntegral numVertices)
56+
return $
57+
Descriptor triangles (fromIntegral firstIndex) (fromIntegral numVertices)
5558

5659
display :: Descriptor -> DisplayCallback
5760
display (Descriptor triangles firstIndex numVertices) = do

0 commit comments

Comments
 (0)