OpenGL provides nice real-time graphics primitives, but to get started with OpenGL you have to first get an OpenGL rendering context on the screen.
For years the simplest cross-platform way to do this was by using the GLUT library. GLUT is unattractive for reasons I'll explain towards the end, but it's easy to get started using it. This tends to make it a nice choice for beginners. These days there are many alternatives to GLUT for those of us who want simplicity and cross-platform compatibility. Here I will focus on Haskell options.
Full spreadsheet view here.
The significance of the license columns is that pure Haskell code which has a standard LGPL license forces your binaries to also abide by the LGPL restrictions. This is due to GHC's cross-module inlining. On the other hand, if a foreign library has an LGPL license but BSD3 Haskell bindings then this does not apply. See for example, the SDL bindings. License entries that read "LGPL with linking exception" mean that using it with Haskell code does not cause your binaries to fall under LGPL restrictions due to the license explicitly granting that exception.
The use of atexit() can lead to subtle problems so I've tried to highlight which libraries use it. Please let me know if you see a mistake in my categorizing the use of atexit().
The requirement of extra libraries is more of a hassle for people who will use cabal-install to get and build your program. If your project is a popular one with a large audience you will want to create an installer for end-users, in which case you could offer to install the extra libraries when they install your program.
For simple uses, such as learning or demos programs, my current recommendation is GLFW-b. SDL also makes a nice choice, but it requires more from your windows users as they will have to install the libraries separately. Linux and OSX users will have to install the libraries but they have the option of using a package manager to handle the install.
Gtk2hs and wxHaskell are harder for novices as they come with restrictions to what you can do. For example, at one point in time gtk2hs programs had to be very careful when using threading. I don't know if this is still an issue though.
Surprisingly, all of the libraries in my table have good documentation. Although, in some cases the Haskell bindings themselves do not have documentation. Typically it's not an issue to go by the original library docs.
GLUT is attractive, in part because it's well known, it's included in the Haskell Platform, and lots of documentation and examples exist. Keep in mind, it's technically not free software (although the source is available), it uses atexit(), and even though it's included in the Haskell Platform windows users will still need to download glut32.dll and install it in their application build directory. If you have the urge to use GLUT, try to use freeglut as your implementation.
Based on the above list of offers, you can see that it would be very nice if someone created a library based on the APIs of GLFW, SDL, or GLUT, but did a direct binding to the native APIs of windows, OSX, and linux so that we'd have a "pure" Haskell option that doesn't require extra C libraries. For this to become a nice solution it would be nice if the Haskell Platform bundled a binding to native OSX APIs.
I hope the above comparisons help you to pick the right GUI library for your next project that uses OpenGL!
Subscribe to:
Post Comments (Atom)
This is a very useful post. I've also been asking myself these questions. The lack of GLUT on Windows was a wrinkle that I thought we'd always have to live with, but your table makes GLFW-b look very attractive. In fact, I wonder why you say that GLFW-b is intended only for simple uses. Of course GLUT isn't used in bug industry, but I've always seen it as a solid cross-platform solution for small, possibly commercial, or open-source, products. I say this as GLUT has also laboured under the label of being useful mainly for learning and demos.
ReplyDeleteWith a name like GLFW-b, I'd guess stability may also be an issue. Lastly, I assume GLUT is now taken as a synonym for FreeGLUT? I ask as I thought FreeGLUT could avoid atexit(); though I may be wrong...
Perhaps you could do an update sometime in the future to see how the landscape evolves.
@PGK: Hi, I'm the GLFW-b maintainer. I'm sorry if the -b suffix makes GLFW-b seem beta; that wasn't my intention. I just needed to differentiate it from the existing bindings (which I also worked on). I think the current implementation is pretty strong and should stay pretty stable.
ReplyDeleteI'm always looking for ways to improve the packages I maintain, so if you have ideas, please don't hesitate to mail me. Thanks.
Jason, I think the GLFW-OGL description may be in the wrong column.
ReplyDelete@PKG, The main reason why I suggest that GLUT/GLFW are mainly useful for smaller programs is that they don't really give you access to the underlying GUI apis. So adding buttons and widgets tends to require additional libraries.
ReplyDeleteAlso, I wasn't aware that freeglut can avoid atexit(). I'll have to research that. These days you can still get the original glut binaries and source. In fact, they come up ahead of freeglut if you're just googling for "glut". So perhaps I should edit the text to clarify which implementation I'm referring at various points in the text.
@brian314, I just got lazy and didn't fill out the details for GLFW-OGL because as far as I can tell it's identical to GLFW except it uses OGL.
There is also a very nice Gloss library which may be the easiest solution for beginners: http://hackage.haskell.org/package/gloss
ReplyDeleteIt uses GLUT/OpenGL internally, but allows to program interactive graphics applications in really simple way; it has very limited support for fonts, so is not suitable for "serious" applications.
And if we talk about GUI toolkits, there is also http://hackage.haskell.org/package/uni-htk, which is much easier to install than gtk2hs or wxcore, but needs a maintainer. Any news about qtHaskell?
@Сергей, I wasn't sure if I should include gloss because as you point out it uses GLUT and I already covered that.
ReplyDeleteI hadn't heard of uni-htk, I'll have to look at it and update my table.
As for qtHaskell, I take the stance that if it's not on hackage it doesn't exist!
Thanks for the comments.
X11 is available on Win32, all you have to do is to install X server on it. There are a couple out there, for example Xming. Just google "win32 xserver".
ReplyDelete@Tener, fair enough. I updated the table.
ReplyDelete@dagitj: Thanks for the clarification: In days gone by I didn't mind the lack of a GUI API...
ReplyDelete@brian314 I will look into GLFW-b in a few months.