是否有一個簡單的完整的代碼示例使用任何gui工具包(這將在Linux和Windows中工作)同時打開多個opengl窗口?當然,如何分開處理他們的事件。我天真地嘗試了它,它崩潰了。如何在具有多個窗口的Haskell中使用OpenGL?
我收到了一個完整的工作源代碼示例從某人之外的計算器。我在這裏粘貼它爲所有人受益。在wxWidgets中
module Main where
import Graphics.UI.GLUT
import System.Exit (exitWith, ExitCode(ExitSuccess))
reshape :: ReshapeCallback
reshape size = do
viewport $= (Position 0 0, size)
matrixMode $= Projection
loadIdentity
frustum (-1) 1 (-1) 1 1.5 20
matrixMode $= Modelview 0
keyboard :: KeyboardMouseCallback
keyboard (Char '\27') Down _ _ = exitWith ExitSuccess
keyboard _ _ _ _ = return()
renderCube :: Color3 GLfloat -> IO()
renderCube c = do
clear [ ColorBuffer ]
let color3f = color :: Color3 GLfloat -> IO()
scalef = scale :: GLfloat -> GLfloat -> GLfloat -> IO()
color3f c
loadIdentity
lookAt (Vertex3 0 0 5) (Vertex3 0 0 0) (Vector3 0 1 0)
scalef 1 2 1
renderObject Wireframe (Cube 1)
flush
displayR :: DisplayCallback
displayR = renderCube (Color3 1 0 0)
displayB :: DisplayCallback
displayB = renderCube (Color3 0 0 1)
createWindowWithDisplayFunc :: String -> Position -> DisplayCallback -> IO Window
createWindowWithDisplayFunc name pos display = do
win <- createWindow name
windowPosition $= pos
clearColor $= Color4 0 0 0 0
shadeModel $= Flat
displayCallback $= display
reshapeCallback $= Just reshape
keyboardMouseCallback $= Just keyboard
return win
main = do
getArgsAndInitialize
initialDisplayMode $= [ SingleBuffered, RGBMode ]
initialWindowSize $= Size 100 100
initialWindowPosition $= Position 100 100
createWindowWithDisplayFunc "R" (Position 10 10) displayR
createWindowWithDisplayFunc "B" (Position 110 10) displayB
mainLoop
這個曾經用在`wxcore` http://hackage.haskell.org/package/wxcore-0.11.1.2我只用過一個窗口,但它運行良好。您可能需要跟進開發人員,看看爲什麼它被丟棄。 – Anthony 2011-02-02 17:27:04
謝謝。我已經改變了這個問題,所以它不是特定的。 – mentics 2011-02-02 18:28:10