为什么我的点不显示在Haskell OpenGL中?

时间:2013-10-28 04:08:06

标签: opengl haskell graphics 3d

我正在尝试使用Haskell and OpenGL生成地形。当我运行代码时,它工作(它显示一个黑色窗口),但没有出现点。我哪里错了?

import Data.Int
import Graphics.UI.GLUT

type Terrain = [(GLint, GLint, GLint)]

points = generateFlatTerrain 100 100 0

generateFlatTerrain :: Int32 -> Int32 -> Int32 -> Terrain
generateFlatTerrain width height depth = 
    [(x, y, z) | x <- [1..width], y <- [1..height], z <- [depth]]

drawTerrain :: Terrain -> IO ()
drawTerrain terrain = renderPrimitive Points
                      $ mapM_ (\(x, y, z) -> vertex $ Vertex3 x y z) terrain

main :: IO ()
main = do
  (_progName, _args) <- getArgsAndInitialize
  _window <- createWindow "Hello, world!"
  displayCallback $= display
  mainLoop

display :: DisplayCallback
display = do
  clear [ ColorBuffer ]
  drawTerrain points
  flush

1 个答案:

答案 0 :(得分:1)

最简单的答案是:OpenGL的坐标空间为[-1..1]。因此我修改了我的代码:

[-1, -1 + 1 / width,..1], ......