gpt4 book ai didi

user-interface - 如何在具有多个窗口的 Haskell 中使用 OpenGL?

转载 作者:行者123 更新时间:2023-12-04 04:26:12 29 4
gpt4 key购买 nike

是否有使用任何 gui 工具包(适用于 Linux 和 Windows)同时打开多个 opengl 窗口的简单完整代码示例?当然还有如何分别处理他们的事件等等。我天真地尝试了它,但它崩溃了。

我从 stackoverflow 以外的人那里收到了完整的工作源代码示例。我把它贴在这里是为了让所有人受益。

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

最佳答案

当然是过剩了。

GLUT homepage

The toolkit supports:
- Multiple windows for OpenGL rendering
- Callback driven event processing
- Sophisticated input devices
- An 'idle' routine and timers
- A simple, cascading pop-up menu facility
- Utility routines to generate various solid and wire frame objects
- Support for bitmap and stroke fonts
- Miscellaneous window management functions

因此您可以使用 GLUT 来管理多个窗口(我曾经使用过一次)。 Here是您需要的教程。

我还找到了 this您可能会看一下这篇文章,因为它是特定于 Haskell 的。

关于user-interface - 如何在具有多个窗口的 Haskell 中使用 OpenGL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4856531/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com