GL utilities, toolkits, and questions..

Hi again, given GL's separation of low-level features and other useful stuff, there are a lot of GL utilities around that make GL life less painful. I've been wondering whether anyone is working on making some of those available or willing to share their own hacks in those areas. Typical examples: 1. fonts.. there are n+1 ways to make fonts with GL, so of course none of them are part of the standard fortunately, GLUT has some minimal support, but there must be GL bindings to/converters from free fonts (or at least system fonts:-( around. * aside: there's something odd with GLUT's stroke font width. * HOpenGL returns that as an Int, which seems to match the spec, * but doesn't make sense to me.. "width in pixels" of a stroke * font??? is that a copy and paste error from the preceding * section on bitmap fonts? * oh, and why is the default stroke font size so huge? I have * to scale it down by a factor of 100, it seems, to get into * natural proportions.. 2. snapshots/printing.. again, GL provides only the foundations we all want to show what we do to people who don't have GHC, GLUT, .. of course, you can snapshot static scenes using system tools, but it would be nicer to produce snapshots, preferredly animated (what format, though?), from within HOpenGL. using feedback from the framebuffer, that seems possible. The GL pages also talk about printer-resolution printing by rendering the scene in tiles. could one export 2d-vector graphics (postscript/SVG) from HOpenGL, or always just pixmaps? 3. scene graph libraries.. who wants to play with all the low-level details all the time? as it happens, I'm working on this part;-) work in progress, but see http://www.cs.ukc.ac.uk/people/staff/cr3/FunWorlds/ for outlines of where I'm headed with this. no screen shots yet (see 2 for why), so here's a brief summary of the state of things - static scene graphs and translation to HOpenGL: are relatively straightforward, and I had some experience with VRML-style scene graphs, so that part only grows on demand - dynamic scene graphs: if you've seen my earlier experiments with FunWorlds/VRML, you know that I'm playing with Fran concepts here, but I've now made some modifications to Fran basic, with which I'm quite happy so far (that's the research aspect and hence the current focus) 4. shadows? there seem to be several techniques - is any of them generally applicable (not just shadows on static planes) and portable? 5. GUIs? Sven mentioned several a while ago, one of which looked quite reasonable. 6. others?-) And while we're at it (some have started already): what are you doing/hoping to do with HOpenGL (not just dozens of private versions of Haskell DOOM, I hope?-)? Claus

On Tue, 09 Jul 2002 21:32:27 +0100
"C.Reinke"
* oh, and why is the default stroke font size so huge? I have * to scale it down by a factor of 100, it seems, to get into * natural proportions..
Could you please post some text rendering example? I am not sure to have understood it well. Maybe it's better you send it to my private address. I have to say that hopengl is really comfortable, the strong typing gives a different feeling, like you can trust what you just wrote. I am going to write a simple file manager in haskell, it is simple indeed, but I am not able to decide where to place rendered text and how to scale it, so I would like your example. I have 0.1 knowledge of opengl, as you might have noticed, but I am willing to learn, don't worry, if you have a working example it's just easier :) If I have a working prototype soon I'll tell it to the M.L. of course. Thank you Vincenzo

On Tue, 09 Jul 2002 21:32:27 +0100 "C.Reinke"
wrote: * oh, and why is the default stroke font size so huge? I have * to scale it down by a factor of 100, it seems, to get into * natural proportions..
Could you please post some text rendering example? I am not sure to have understood it well. Maybe it's better you send it to my private address.
Sure. Here's the part of my current prototype dealing with Text nodes in the scene graph (where strs is a list of Strings): render context@(RC{t=t,lights=l,sources=srcs,keyb=keyb}) (Text strs) = do pushMatrix scale fontFudge fontFudge fontFudge sequence_ [pushMatrix >> strokeString StrokeRoman str >> popMatrix >> translate gap | str <- strs] popMatrix return (context, Text strs) where fontFudge = 1/105::GLdouble gap = Vector3 0 (-125) 0 :: Vector3 GLdouble So, basically, it's just "strokeString StrokeRoman <your String>", with few variations (e.g., using bitmapped fonts instead). It'll also translate your position to the end of the String. You'll notice that I have to scale down the text to get it roughly to the unit size of GLUT's cubes, and that I use a rather silly nested transformation scope to hide the translations done by stroking the Strings because of the other strangeness I mentioned (the width of stroked Strings being returned as a bitsize..).
I have to say that hopengl is really comfortable, the strong typing gives a different feeling, like you can trust what you just wrote.
No complaints about Sven's work!-) But I think we thank him best by building on the foundations he laid, so that the functionality may be accessed at more abstract levels, e.g. declarative scene graphs compiled down into streams of HOpenGL-instructions, as indicated above. That way, he'll be able to profit from our work as we from his. Currently, it's more like a teaser trailer than anything useful, but I've now added some boring screen shots and code to my FunWorlds page http://www.cs.ukc.ac.uk/people/staff/cr3/FunWorlds/ (the library itself desperately needs some rudimentary documentation before I can release it, and lots of functionality added afterwards, and of course I'll keep testing and modifying the design ideas:).
I am going to write a simple file manager in haskell, it is simple indeed, but I am not able to decide where to place rendered text and how to scale it, so I would like your example.
For a file manager (btw, I've found standard Haskell file access functionality very limited, but GHC's should be a lot more practical), you'll want 2d representations, orthogonal projections, and well-antialiased bitmapped fonts, so your requirements differ from mine - HOpenGL is a wide playing field!-) But GLUT's bitmapped fonts might be an acceptable starting point (just), and are just as easy to use as its stroked fonts. Here are some relevant links http://www.opengl.org/developers/code/features/fontsurvey/ http://www.opengl.org/developers/code/mjktips/TexFont/TexFont.html http://homepages.paradise.net.nz/henryj/code/index.html#FTGL http://oglft.sourceforge.net/ Bindings to one of the latter two would be really nice, but they also seem to add new dependencies (on the libraries themselves, and on the FreeType software they build on..). Also, look through the HOpenGL mailing list archive for the links to OpenGL-based GUIs Sven posted a while ago. Binding to one of those would be of general interest (just as fonts..) and might make the file manager problem easier: http://www.sjbaker.org/steve/omniv/mui_pui_glui.html http://www.cs.unc.edu/~rademach/glui/
I have 0.1 knowledge of opengl, as you might have noticed, but I am willing to learn, don't worry, if you have a working example it's just easier :)
We are all learning, but it's a lot of fun!-) The interface to GLUT fonts is so trivial that its spec is already an example, mostly because there isn't much functionality.. http://www.opengl.org/developers/documentation/glut/index.html (see HOpenGL-1.02/lib/GLUT_Fonts.hs for Sven's adaptation)
If I have a working prototype soon I'll tell it to the M.L. of course.
Looking forward to all news about HOpenGL projects.
There's one thing I forgot to say: I will have some spare time in august, maybe I could writer an haskell interface to one of the font renderers available for opengl.
Is this a good moment, or should I wait for FFI?
If we believe the marketing hype, ghc-5.04.1 will have what it takes, and the FFI spec is stable (they say..). Cheers, Claus

For a file manager (btw, I've found standard Haskell file access functionality very limited, but GHC's should be a lot more practical), you'll want 2d representations, orthogonal projections, and well-antialiased bitmapped fonts, so your requirements differ from mine - HOpenGL is a wide playing field!-) But GLUT's bitmapped fonts might be an acceptable starting point (just), and are just as easy to use as its stroked fonts.
I really want to use one of the binding to freetype. My goal is to write a file manager (and then a panel, and a desktop manager) which is fast to develop, and looks nice. I mean: to have the feel of all 2d f.m., but to have 3d enhancements, like transparency, animations and so on; using haskell could allow user-supplied code to be compiled at startup and to be safe (I could limit user code to a monad with few operations, which can't do IO for example). So, I need opengl to render everything and maybe my project will become some form of "cool widget set" itself. For now, it's just an idea, nothing more. And I think that any amatorial plan needs to have functionalities "on demand": I start writing a file manager, and implement everything related, avoiding to bother of anything else. I'm not sure I will succeed, yes, but I want to try.
Here are some relevant links
http://homepages.paradise.net.nz/henryj/code/index.html#FTGL http://oglft.sourceforge.net/
I've seen that oglft needs qt (which is not GPL on all platforms) to be able to use unicode. It's a trouble. And FTGL does not mention unicode, I 'm going to download it, surely.
Bindings to one of the latter two would be really nice, but they also seem to add new dependencies (on the libraries themselves, and on the FreeType software they build on..).
I don't think it's a problem. Reuse adds dependencies, but simplifies coding.
Is this a good moment, or should I wait for FFI?
If we believe the marketing hype, ghc-5.04.1 will have what it takes, and the FFI spec is stable (they say..).
Yes, but (as far as I know) ghc's FFI is not implemented in other haskell systems (or am I wrong?). I mean, is there a standardized way to call foreign code? Am I wrong? Thanks for your explanations of the GLUT font system... it's better now ;) I didn't understand that rendering a character implicitly uses "GLtranslate" so I didn't "pushMatrix" and "popMatrix"... it's really better now :) Vincenzo

If we believe the marketing hype, ghc-5.04.1 will have what it takes, and the FFI spec is stable (they say..).
Yes, but (as far as I know) ghc's FFI is not implemented in other haskell systems (or am I wrong?).
It is implemented in NHC and in the current CVS copy of Hugs too.
I mean, is there a standardized way to call foreign code? Am I wrong?
When 3 out of 4 Haskell compilers support it, I'd say it is a de facto standard and can be relied upon just as one could (and still can) use GreenCard to generate portable code. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/

Nick Name
Is this a good moment, or should I wait for FFI?
If we believe the marketing hype, ghc-5.04.1 will have what it takes, and the FFI spec is stable (they say..).
Yes, but (as far as I know) ghc's FFI is not implemented in other haskell systems (or am I wrong?). I mean, is there a standardized way to call foreign code? Am I wrong?
GHC 5.04 implements the proposed standard FFI. Hugs is currently being brought in line by Alastair Reid and nhc98 has it on its todo list. This is as close to a standard as you'll get at the moment. For anything OpenGL related, I would recommend to take exactly the same route as Sven has done. Consistency is good! Cheers, Manuel

C.Reinke wrote:
* oh, and why is the default stroke font size so huge? I have * to scale it down by a factor of 100, it seems, to get into * natural proportions..
Well, I guess the size itself is not a bug, but a feature of GLUT. But there is an inconsistency: The spec for glutStrokeCharacter http://www.opengl.org/developers/documentation/glut/spec3/node78.html talks about "units" (of magnitude 100, as you've already noticed), while the spec for glutStrokeWidth http://www.opengl.org/developers/documentation/glut/spec3/node79.html talks about "pixels". The latter is probably a cut-n-paste bug from the spec for glutBitmapWidth.
[...] Binding to one of those would be of general interest (just as fonts..) and might make the file manager problem easier:
http://www.sjbaker.org/steve/omniv/mui_pui_glui.html http://www.cs.unc.edu/~rademach/glui/
The latter is already on my (rather long :-} TODO list, but things are complicated by the fact that no Linux distribution or any other OS I know of comes with a pre-installed GLUI. Requiring a potential UI programmer to download and install it first would vastly lower the acceptance of the binding. Consequently the way to go is to ship the Haskell binding with the library itself. This is not such a big deal as it might sound, the object files on Linux are about 260kB, i.e. almost nothing compared to the probable size of the Haskell part.
[...] If we believe the marketing hype, ghc-5.04.1 will have what it takes,
The just released GHC 5.04 has spec-conforming FFI support, as does the CVS version of Hugs. NHC98 almost has it IIRC, but I'm not sure about this. Simply ask Malcolm about this.
and the FFI spec is stable (they say..).
Apart from some esoteric features and occasional clarifications the spec is indeed very stable. Cheers, S.

On Sun, 21 Jul 2002 20:10:05 +0200
Sven Panne
The just released GHC 5.04 has spec-conforming FFI support, as does the CVS version of Hugs. NHC98 almost has it IIRC, but I'm not sure about this. Simply ask Malcolm about this.
and the FFI spec is stable (they say..).
Apart from some esoteric features and occasional clarifications the spec is indeed very stable.
Good. BTW I don't think it's a good idea to write bindings for a widget set, because they're written in C, and could take bugs and segfaults. Font renderer are far more complicated and I am surely not able to write them, and besides they require high efficiency. For widget sets, I think it's better to develop a UI model totally independent from the graphics library , for example copying that of Fudgets, or of IHaskell, and then implement it in HOpenGL. Maybe the implementation should be parametric in respect to the functions used to draw (we could have "themes" which can change the behavior of the library). It's just my humble opinion Vincenzo

Good. BTW I don't think it's a good idea to write bindings for a widget set, because they're written in C, and could take bugs and segfaults.
I disagree rather strongly (which is why I've spent so much time over the last 8 or 9 years working on interfacing Haskell to C). It takes a lot of effort to develop a good library. You spend a lot of time on design, implementation, bugfixing, figuring out interactions with other libraries/ software, documenting it, writing tutorials, getting publishers to accept books about it, revising the design, performance tuning, etc. I don't think it makes sense to repeat that effort unless there is some clear benefit to be had. This benefit can include (in fact, usually consist of) things like getting a PhD, exploring a new design style, demonstrating feasability, etc. but it's hard to develop a product which is of higher quality than one in which so much time has already been invested. In the specific case of widget sets, two important goals are maintaining the same look and feel (whether one likes it or not) and maintaining the same interface with configuration mechanisms as on the system you are developing for. And, when Haskell is the implementation language, we should consider resource usage, long term memory behaviour and behaviour under stress: when the machine is thrashing, when handling exceptions, when the thread allocation limit is reached, etc. (I single Haskell out here because by making more things implicit than many other languages, Haskell makes it harder to reason about and deal with failure.) For this reason, I think it makes a lot more sense to incorporate existing libraries into Haskell and then build cleaner layers on top. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/

It takes a lot of effort to develop a good library.
First of all, from now on, I want to point out that I am not so good at english, so I'll be often unclear. I am really sorry for this. And, I've not been unclear, just excessive in what I said. I am not criticizing anything, I've used GLUI in the past and found it fast and bugfree, for example. What I had in mind, and didn't say, is that it *might be* that reimplementing GLUI in haskell, following its design principles, could take less time than one could imagine, and bring a type-safe implementation. This is not true for QT, for example, which is full of so many functionalities no one can think of re-implementing it. Anyway I am not willing to reimplement GLUI, so it was not a critique, just my opinion (and I am just a computer science student, undergraduated, so my opinion doesn't matter so much :). Of course, It absolutely wasn't a critique of FFI in Haskell. It's not only useful but also necessary, for example for OpenGL or OpenAL, without counting that, even if GTK is NOT bugfree, there are many people that want or *need* to program for gtk, and could be interested in haskell. And, it's a programmer's choice what to consider part of the bare machine (and write an FFI binding) and what to consider "the software" and prefer to write it in haskell. What I am looking forward is to take an "haskell like" UI design and implement it, but parametrized in respect to the actions to be taken. So it could be reasonable to implement my design by myself, a binding for GLUI, and to instantiate my more abstract design using calls to GLUI (whose binding would surely result in a very "imperative" feeling). And, on the other side, to implement some "cool" widget in haskell+opengl, using the visual enhancements that opengl can give, and to instantiate the abstract UI with this widget set. In fact I am using console stubs by now, because I'm focusing on what structure is better for a file manager. An haskell program written for the abstract UI could then use one or another. It's just an experiment, I want to keep things well separated.
when the machine is thrashing, when handling exceptions, when the thread allocation limit is reached, etc. (I single Haskell out here because by making more things implicit than many other languages, Haskell makes it harder to reason about and deal with failure.)
It's a problem, but it's what we have to study. We cannot think that nothing serious can be done in Haskell because memory exhaustion would crash the program. Yes, I still have to read the articles around about imprecise exceptions ...
For this reason, I think it makes a lot more sense to incorporate existing libraries into Haskell and then build cleaner layers on top.
Yes, in fact, I am going to split my UI to allow this, but I want to play with opengl and have a funny toy-like visually-astonishing opengl widget set. Nothing more than that. And, besides, I know I won't succeed, but I have to try. If someone else will make a binding for GLUI I will ensure that my "clean" design (I am almost sure I will copy fudgets or ih, just let me some time to study both) will be implementable with GLUI. I need to clarify that I spoke too fast, and made a mistake. What I want to do in my spare time is a binding to a font library because *I* consider it more important. But this doesn't mean this isn't important, I agree. Vincenzo Ciancia

There's one thing I forgot to say: I will have some spare time in august, maybe I could writer an haskell interface to one of the font renderers available for opengl. Is this a good moment, or should I wait for FFI? Anyone can suggest what FFI I should eventually use? Thanks. Vincenzo Ciancia

Anyone can suggest what FFI I should eventually use?
There's only one ffi. But if you want an ffi _frontend_, I'd point out that GreenCard is portable, stable, provides a clean Haskell-style interface (e.g., result codes are readily translated into Haskell exceptions), and generates portable code. Of course, I'm biased since I'm one of the authors. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/

On 22 Jul 2002 17:45:31 +0100
Alastair Reid
There's only one ffi
Oh yes, I meant frontend, just I wanted to know if ffi is accepted and stable or "nearly finished" (and so it could change) as written on http://www.haskell.org/libraries/ but yes I trust greencard... should the ffi change greencard will not, right? I am sorry to having bothered you, I'm just a newbie... an experienced newbie :) Vincenzo Ciancia

Oh yes, I meant frontend, just I wanted to know if ffi is accepted and stable or "nearly finished" (and so it could change) as written on
I foresee some small changes based on the experience creating a third implementation.
but yes I trust greencard... should the ffi change greencard will not, right?
Right. I can imagine tweaking the internals to generate threadsafe code (not previously a problem since compilers didn't generate threaded code) and the ffi distinguishes three levels of 'safety' whereas greencard only distinguishes two so there'll be a change there too. [btw The other ffi frontends are worth looking at too but I don't know them as well.] -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/

And while we're at it (some have started already): what are you doing/hoping to do with HOpenGL (not just dozens of private versions of Haskell DOOM, I hope?-)?
Surely not! :) In the last weeks I've been re-structuring FunGEn completely (that's why it is taking so long for version 0.2 to be released). I read Mark's CGL (Clean Game Library) thesis and found a lot of useful information and ideas. The main objective is to make FunGEn a engine that deals much more with worlds/leves/objects SPECIFICATIONS rather than programming all the stuff in a IMPERATIVE way (actually, its first version had a little bit of it). BTW, I've got no FunGEn feedback at all (apart from Sven's notes just after releasing)... :( -- Andre

In the last weeks I've been re-structuring FunGEn completely (that's why it is taking so long for version 0.2 to be released). I read Mark's CGL (Clean Game Library) thesis and found a lot of useful information and ideas. The main objective is to make FunGEn a engine that deals much more with worlds/leves/objects SPECIFICATIONS rather than programming all the stuff in a IMPERATIVE way (actually, its first version had a little bit of it).
BTW, I've got no FunGEn feedback at all (apart from Sven's notes just after releasing)... :(
Sorry, I booked it as "great, but not down my alley" - didn't reckon that a game engine would build on a kind of scene graph as well, even if in 2d. How do you deal with animating the scene graph? The combination of declarative descriptions of scene graphs, animation, and reactivity were just what Fran was designed for, but it has traditionally posed some problems in efficient implementation. I think those have their source in unfortunate aspects of Fran's design which I'm currently trying to overcome. Guess I'll have to take a closer look at your stuff soon, but from your FunGEn 0.1 example at http://www.cin.ufpe.br/~haskell/fungen/example.html it seems you've got separate data structures describing the game resources, the collections of game objects and the possible inputs (the later bundled with their callbacks). The timing functionality looks like a thin wrapper around the two GLUT timing callbacks? The game object actions are then written as monadic actions with easy access to other objects' properties. If that summary is not too far off, FunGEn 0.1 is still a mixture of declarative and imperative descriptions. Will that change with FunGEn 0.2? Game hackers might welcome the familiar style (as long as noone tells them they'd be using monads;-). Cheers, Claus

Thanks for you feedback, Claus! Answering your questions:
The timing functionality looks like a thin wrapper around the two GLUT timing callbacks?
Yes, you're right. The Fun_Timer module is still very simple, but I'm sure that there are lots of functionalities waiting to be added.
The game object actions are then written as monadic actions with easy access to other objects' properties.
Yes, and that's the point I think will change considerably.
If that summary is not too far off, FunGEn 0.1 is still a mixture of declarative and imperative descriptions. Will that change with FunGEn 0.2?
As said before in the last answer, yes. I'd suggest you to check the Clean Game Library (http://www.cs.kun.nl/~clean/platformgameinfo.html) for more info about what's comming. Thanks, -- Andre

On Sat, 20 Jul 2002 13:43:02 -0300
"Andre W B Furtado"
SPECIFICATIONS rather than programming all the stuff in a IMPERATIVE way (actually, its first version had a little bit of it).
Yes, I noticed that the pong example was a little "imperative" ;)
BTW, I've got no FunGEn feedback at all (apart from Sven's notes just after releasing)... :(
I am looking forward to experiment with it, but if you are rewriting I need to wait. Why don't you get a sourceforge account so you can get a cvs server? Vincenzo
participants (6)
-
Alastair Reid
-
Andre W B Furtado
-
C.Reinke
-
Manuel M T Chakravarty
-
Nick Name
-
Sven Panne