User interface 如何在Haskell中多窗口使用OpenGL?

User interface 如何在Haskell中多窗口使用OpenGL?,user-interface,opengl,haskell,User Interface,Opengl,Haskell,是否有一个简单完整的代码示例使用任何gui工具包(可以在Linux和Windows中工作)同时打开多个opengl窗口?当然还有如何分别处理他们的事件等等。我天真地尝试了一下,结果失败了 我从stackoverflow之外的人那里收到了一个完整的工作源代码示例。我把它贴在这里是为了大家的利益 module Main where import Graphics.UI.GLUT import System.Exit (exitWith, ExitCode(ExitSuccess)) reshap

是否有一个简单完整的代码示例使用任何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
modulemain其中
导入Graphics.UI.GLUT
导入系统。退出(exitWith,ExitCode(ExitAccess))
重塑::重塑Callback
重塑尺寸=do
视口$=(位置0,大小)
矩阵模式$=投影
负载标识
平截体(-1)1(-1)11.5 20
matrixMode$=Modelview 0
键盘::键盘鼠标返回
键盘(字符'\27')向下\uuu=exitWith ExitSuccess
键盘=返回()
renderCube::Color3 GLfloat->IO()
renderCube c=do
清除[颜色缓冲区]
让color3f=color::Color3 GLfloat->IO()
scalef=scale::GLfloat->GLfloat->GLfloat->IO()
彩色3F c
负载标识
注视(顶点3 0 5)(顶点3 0 0 0)(向量3 0 1 0)
scalef 1 2 1
渲染对象线框(立方体1)
脸红
displayR::DisplayCallback
displayR=renderCube(颜色3 1 0 0)
displayB::DisplayCallback
displayB=renderCube(颜色3 0 0 1)
createWindowWithDisplayFunc::字符串->位置->显示回调->IO窗口
createWindowWithDisplayFunc name pos display=do

wxWidgets中的winOpenGL支持使用的是。不幸的是,它似乎不存在于
wx
包中。您可以在代码< > WX包和C++用法示例中引用其他控件,而不太困难,当然,

GLUT,当然。

美国

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


我还发现了一篇文章,您可能会看一看,因为它是Haskell特有的。

这篇文章以前在
wxcore
中,我只在单个窗口中使用过它,但效果很好。您可能需要与开发人员联系,了解它被删除的原因。谢谢。我把问题改了,所以不是针对wx的。谢谢。我要求提供一个Haskell代码示例,但powerpoint似乎可以翻译accross。我将尝试一下,并将结果发布在这里。
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