我正在使用 OpenGl 和 Haskell 编写一个程序,它应该在单击鼠标的时间和位置绘制一个矩形。但是,程序在我单击并在绘制矩形之前关闭。
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Graphics.UI.GLUT.Callbacks.Window
main = do
(progname, _) <- getArgsAndInitialize
createWindow progname
keyboardMouseCallback $= Just myKeyboardMouseCallback
displayCallback $= display
mainLoop
myKeyboardMouseCallback key keyState modifiers (Position x y) =
case (key, keyState) of
(MouseButton LeftButton, Down) -> do
clear[ColorBuffer]
let x = x :: GLfloat
let y = y :: GLfloat
renderPrimitive Quads $ do
color $ (Color3 (1.0::GLfloat) 0 0)
vertex $ (Vertex3 (x::GLfloat) y 0)
vertex $ (Vertex3 (x::GLfloat) (y+0.2) 0)
vertex $ (Vertex3 ((x+0.2)::GLfloat) (y+0.2) 0)
vertex $ (Vertex3 ((x+0.2)::GLfloat) y 0)
flush
_ -> return ()
display = do
clear [ColorBuffer]
renderPrimitive Lines $ do
flush
是否有什么东西导致程序在其中一种方法中提前终止,或者这只是计算机告诉我我不能这样做的方式?