Re: [Haskell-cafe] renderString problems
On Wednesday 01 August 2007 18:30, Dave Tapley wrote: I'm having a lot of trouble using renderString from Graphics.UI.GLUT.Fonts. All my attempts to render a StrokeFont have so far failed. Using a BitmapFont I can get strings to appear but they demonstrate the odd behaviour of translating themselves a distance equal to their length every time my displayCallback function is evaluated. This is actually not a bug, but a feature. :-) From the Haddock docs for renderString: Render the string in the named font, without using any display lists. Rendering a nonexistent character has no effect. If the font is a bitmap font, renderString automatically sets the OpenGL unpack pixel storage modes it needs appropriately and saves and restores the previous modes before returning. The generated call to bitmap will adjust the current raster position based on the width of the string. If the font is a stroke font, translate is used to translate the current model view matrix to advance the width of the string. The rational behind this is that you set a position once, and subsequent multiple renderString calls will render the individual strings one after the other, just like printf appends strings on the output. If this is not clear from the documentation, any suggestions how to improve the docs? And another hint: On usual consumer graphic cards, stroke fonts are normally faster than bitmapped fonts. The fastest, most flexible (scaling, filtering, ...) and visually nicest option would be textured quads, but this is not supported by GLUT. My requests are: * Does anyone know how to keep the position fixed? For bitmapped fonts, explicitly set the currentRasterPosition. For stroke fonts, you can use the normal modelview machinery (loadIdentity/preservingMatrix/...). * Are there any good examples of (working) GLUT code available on the web, I'm finding it very hard to make any progress at the moment. Certainly not at Haskell speed :( Depending on the distribution you use, you probably have the example already somewhere on your disk or you can directly have a look at the repository: http://darcs.haskell.org/packages/GLUT/examples/ Cheers, S. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] renderString problems
On 8/26/07, Sven Panne [EMAIL PROTECTED] wrote: This is actually not a bug, but a feature. :-) From the Haddock docs for renderString: Render the string in the named font, without using any display lists. Rendering a nonexistent character has no effect. If the font is a bitmap font, renderString automatically sets the OpenGL unpack pixel storage modes it needs appropriately and saves and restores the previous modes before returning. The generated call to bitmap will adjust the current raster position based on the width of the string. If the font is a stroke font, translate is used to translate the current model view matrix to advance the width of the string. The rational behind this is that you set a position once, and subsequent multiple renderString calls will render the individual strings one after the other, just like printf appends strings on the output. If this is not clear from the documentation, any suggestions how to improve the docs? Why not add the rationale to the docs too? Invoking printf should make the thing jump into focus for anyone who hasn't got it. martin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] renderString problems
On 8/2/07, Dave Tapley [EMAIL PROTECTED] wrote: Using a BitmapFont I can get strings to appear but they demonstrate the odd behaviour of translating themselves a distance equal to their length every time my displayCallback function is evaluated. I've never used OpenGL from Haskell, but it sounds like renderString is modifying your modelview matrix with each call, presumably to make it easier to chain lots of text together in one frame. Since the matrix never gets reset, the translation effect accumulates each time the scene is redrawn. The quick fix would be to call loadIdentity (i.e. glLoadIdentity) each time you update, before drawing anything. Stuart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] renderString problems
Hi Dave, everyone... Dave Tapley wrote: Hi all, I'm having a lot of trouble using renderString from Graphics.UI.GLUT.Fonts. All my attempts to render a StrokeFont have so far failed. Using a BitmapFont I can get strings to appear but they demonstrate the odd behaviour of translating themselves a distance equal to their length every time my displayCallback function is evaluated. My requests are: * Does anyone know how to keep the position fixed? One way is to wrap the drawing action with preservingMatrix : http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-CoordTrans.html#v%3ApreservingMatrix (re-exported from the main GLUT module, if I read the docs correctly) This pushes the transformation state to a stack, executes the action, and restores the transformation state from the stack. More useful when you have complex scenes/subscenes/subsubscenes etc, but should work here too. [snip] Claude -- http://claudiusmaximus.goto10.org ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] renderString problems
Your code is not rendering stroke font, but bitmap. Use the following code to render str at x and y position. GL.currentRasterPosition $= vertex4 x y 0 1 GLUT.renderString GLUT.Fixed8By13 str where vertex4 is defined as: vertex4 :: Float - Float - Float - Float - GL.Vertex4 Float vertex4 = GL.Vertex4 Note that the coordinate system for rasterization is different from GL's transformation matrix. If you really want the stroke font, you should use Roman or MonoRoman, then you may transform your position using GL.translate (GL.Vector3 x y 0). Regards, Paul L On 8/1/07, Dave Tapley [EMAIL PROTECTED] wrote: Hi all, I'm having a lot of trouble using renderString from Graphics.UI.GLUT.Fonts. All my attempts to render a StrokeFont have so far failed. Using a BitmapFont I can get strings to appear but they demonstrate the odd behaviour of translating themselves a distance equal to their length every time my displayCallback function is evaluated. My requests are: * Does anyone know how to keep the position fixed? * Are there any good examples of (working) GLUT code available on the web, I'm finding it very hard to make any progress at the moment. Certainly not at Haskell speed :( I am using the following code: import Graphics.UI.GLUT main = do getArgsAndInitialize createWindow displayCallback $= update actionOnWindowClose $= ContinueExectuion mainLoop update = do clear [ColorBuffer] renderString Fixed8By13 $ Test string flush Cheers, Dave ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe