renderString problems

View: New views
3 Messages — Rating Filter:   Alert me  

renderString problems

by Dave Tapley-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
_______________________________________________
HOpenGL mailing list
HOpenGL@...
http://www.haskell.org/mailman/listinfo/hopengl

Re: renderString problems

by C Flynn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 1 Aug 2007, 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?
>  * 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
> _______________________________________________
> HOpenGL mailing list
> HOpenGL@...
> http://www.haskell.org/mailman/listinfo/hopengl
>

I had a similar problem with stroke fonts. Try scaling by a low number
(such as 0.01) and see where that gets you. The problem was it was
rendering them at a size much bigger than my coordinate space that I just
couldn't see them. I'm not convinced you need that $ there either but I
don't suppose it hurts.

Charles
_______________________________________________
HOpenGL mailing list
HOpenGL@...
http://www.haskell.org/mailman/listinfo/hopengl

Re: [Haskell-cafe] renderString problems

by Sven Panne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.
_______________________________________________
HOpenGL mailing list
HOpenGL@...
http://www.haskell.org/mailman/listinfo/hopengl
LightInTheBox - Buy quality products at wholesale price