我正在尝试使用Haskell和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
最简单的答案是:OpenGL的坐标空间是[-1..1]。因此,我修改了我的代码:
[-1, -1 + 1 / width,..1], ......