Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell中的OpenGL VAO初始化_Haskell_Opengl_Functional Programming - Fatal编程技术网

Haskell中的OpenGL VAO初始化

Haskell中的OpenGL VAO初始化,haskell,opengl,functional-programming,Haskell,Opengl,Functional Programming,我正在用Haskell编写一种框架。现在我只是想用OpenGL在屏幕上画一条线。其想法是用户只需编写如下内容: module BBApp ( app ) where import BB.Main line :: Polyline line = newPolyline points :: [Point] points = [Point 2 4 2, Point 89 3 78, Point 32 43 8] constructLine :: Polyline -> Polyline

我正在用Haskell编写一种框架。现在我只是想用OpenGL在屏幕上画一条线。其想法是用户只需编写如下内容:

module BBApp
( app
) where

import BB.Main

line :: Polyline
line = newPolyline

points :: [Point]
points = [Point 2 4 2, Point 89 3 78, Point 32 43 8]

constructLine :: Polyline -> Polyline
constructLine line = addPoints points line

app :: App 
app = do
    draw . constructLine $ line
data Polyline = Polyline { points :: [Point], vbo :: Vbo }

newPolyline :: Polyline
newPolyline = Polyline { points = [], vbo = newVbo }
然后,用户编写的
app
将在main中的无限循环中调用

多段线的构造如下所示:

module BBApp
( app
) where

import BB.Main

line :: Polyline
line = newPolyline

points :: [Point]
points = [Point 2 4 2, Point 89 3 78, Point 32 43 8]

constructLine :: Polyline -> Polyline
constructLine line = addPoints points line

app :: App 
app = do
    draw . constructLine $ line
data Polyline = Polyline { points :: [Point], vbo :: Vbo }

newPolyline :: Polyline
newPolyline = Polyline { points = [], vbo = newVbo }
newVbo
使用
glgenvertexarray
Graphics.Rendering.OpenGL.Raw
创建一个新的顶点数组。我的问题是在主循环的每次迭代中都会生成一个新的顶点数组。
如何使我的
多段线
由唯一的顶点数组表示?

假设
Vbo
s在
IO
中分配,则需要
unsafePerformIO
以便在创建纯数据结构时生成
Vbo
。您必须确保在图形内容初始化之前,创建调用不会真正进行;懒惰也许能帮你解决这个问题。嗨@luqui,我读过一些关于
unsafePerformIO
的文章,但我不知道如何使用它。你能说得更具体些吗?