[HOpenGL] GL utilities, toolkits, and questions..

C.Reinke C.Reinke@ukc.ac.uk
Sat, 20 Jul 2002 22:38:48 +0100


> On Tue, 09 Jul 2002 21:32:27 +0100
> "C.Reinke" <C.Reinke@ukc.ac.uk> 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