在 MacOS X 上的 GHCi 中工作的 Haskell 图形库
是否存在满足以下要求的 Haskell 图形库或绑定到外部库:
- 可以从 ghci 使用,即我不必链接并重新启动程序。
- 适用于 MacOS X。(与 1 结合使用很棘手!)
- 可以制作简单的矢量图形(线条、多边形、简单的填充和描边)。
- 可以将位图图像放在屏幕上。示例:blit 17x12 .bmp 图像。
?
请包含一个最小的源代码示例或对其的引用(只是屏幕上的一个窗口,可能在里面画了一条绿线),以便我可以特别检查第 1 点和第 2 点。另外,如果这些功能请求之一更详细(例如 OpenGL + 4),请提供一份很好的参考。
PS:关于1和2,我知道enableGUI
技巧并且我愿意使用它。但是,大多数库都存在无法多次运行 main
函数的问题,因此不符合资格。
编辑:为了避免浪费您的时间,这里列出了我尝试过的软件包:
Does there exist a Haskell graphics library or binding to an external library that fulfills the following requirements:
- Can be used from
ghci
, i.e. I don't have to link and restart the program. - Works on MacOS X. (Tricky in conjunction with 1!)
- Can do simple vector graphics (lines, polygons, simple fills and strokes).
- Can put bitmap images on screen. Example: blit a 17x12 .bmp image.
?
Please include a minimal source code example or a reference to it (just a window on screen, maybe with a green line drawn inside it) so that I can check the points 1. and 2. in particular. Also, if one of these feature requests is more elaborate (for example OpenGL + 4), please include a good reference.
PS: Concerning 1 and 2, I know about the enableGUI
trick and I am willing to use it. However, most libraries have the problem that you can't run the main
function multiple times and hence don't qualify.
Edit: To avoid wasting your time, here a list of packages that I've tried:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否看到过引用的 GLFW http://plucky.cs.yale.edu/soe/软件1.htm
Have you seen the GLFW as referenced http://plucky.cs.yale.edu/soe/software1.htm
有关 Haskell+GUI+OpenGL 的更多信息可在此讨论中找到:
http://www.haskell.org/pipermail/haskell-cafe /2011年5月/091991.html
More information on Haskell+GUI+OpenGL is available in this discussion:
http://www.haskell.org/pipermail/haskell-cafe/2011-May/091991.html
编辑:实际上,我不再确定。几个版本之后,GLFW 似乎不再适用于 OS X 上的 GHCi。
事实证明,GLFW+OpenGL 满足了所有四个要求!
EnableGUI.hs
文件,您可以通过 此处。请注意,您无法将其直接加载到 GHCi 中,您必须首先对其进行编译。这是一个将位图放到屏幕上的小示例。位图有一些限制:其尺寸必须是 2 的幂(此处为 256)并且必须是
.tga
文件(此处为"Bitmap.tga"
) 。但由于支持透明度,所以这不是什么大问题。您应该能够毫无问题地多次调用
main
。关键点是您不应该调用GLFW.terminate
。这是一个示例位图(您需要将其转换为
.tga
)。EDIT: Actually, I'm no longer sure. Several versions later, it seems that GLFW no longer works in GHCi on OS X.
It turns out that GLFW+OpenGL fulfills all four requirements!
ghci -framework Carbon
.EnableGUI.hs
file, which you can get here. Note that you can't load it right into GHCi, you have to comiple it, first.Here is a small example that puts a bitmap onto the screen. There are some restrictions on the bitmap: its dimensions must be a power of two (here 256) and it must be a
.tga
file (here"Bitmap.tga"
). But since transparency is supported, this is not much of a problem.You should be able to call
main
multiple times without problem. The key point is that you should not callGLFW.terminate
.Here an example bitmap (which you need to convert to
.tga
).如果您使用 X11 版本的 gtk2 框架,Gtk2Hs 库可以满足所有要求。
关于要求:
这是一个最小的例子
The Gtk2Hs library fulfills all the requirements if you use the X11 version of the gtk2 framework.
Concerning the requirements:
gtk2
via MacPorts and use the +x11 option (default). (That said, I've had numerous problems installing gtk2 in the past, but this time it seemed to work.)Here a minimal example
截至 2014 年初,我无法在 Mac OS X 中使用 @heinrich-apfelmus 答案。这个 GLFW-b 示例 (链接)但是有效。
因此,请确保您拥有:
并且,如果您尝试了 Apfelmus 的答案,您可能需要
提供
Graphics.UI.GLFW
,并且您将得到一个“不明确的模块名称 'Graphics.UI.GLFW” ’”来自 ghc。然后我尝试了上面的示例程序并且它有效(Mac OS X,10.9,Mavericks)As of early 2014, I wasn't able to use @heinrich-apfelmus answer in Mac OS X. This GLFW-b example (link) however worked.
So, ensure you have:
and, if you tried Apfelmus' answer, you may need to
as both provide
Graphics.UI.GLFW
, and you will get an "Ambiguous module name 'Graphics.UI.GLFW'" from ghc. Then I just tried the sample program above and it worked (Mac OS X, 10.9, Mavericks)