haskell-opengl/GLUT

Can't use fonts in OpenGL

Closed this issue · 7 comments

nh2 commented

Hi, when I want to use any of the inbuilt fonts, with runghc or ghci, I get:

Prelude Main> freeglut (<interactive>): stroke font 0x45f37b20 not found

This seems to be known at least to the Gloss people.

Using ghci is important for what I'm trying to do with this, so I cannot just use ghc for it unfortunately.

Is there anything we can do about this? Do you know what the restriction here is?

I just tested the Stroke.hs example (https://github.com/haskell-opengl/GLUT/blob/master/examples/RedBook4/Stroke.hs) with GHCi on Windows and x86_64 Linux, and it works fine. Therefore I guess it is platform-related and probably a Mac OS X issue. I don't have access to a Mac, so it would be nice if somebody had a look at this, perhaps the cabal file need some tweaking, or it is a GHCi linker issue. Related files:

https://github.com/haskell-opengl/GLUT/blob/master/Graphics/UI/GLUT/Raw/Fonts.hs
https://github.com/haskell-opengl/GLUT/blob/master/cbits/HsGLUT.c

Furthermore, having platform/version details and a repro would be nice (if my guess is wrong).

nh2 commented

@svenpanne I'm actually on Linux x86_64.

The Stroke.hs example you posted works for me, but it doesn't seem to use OpenGL fonts, but rather "render" characters itself from a list of points (see here).

This fails for me:

import Graphics.UI.GLUT

main :: IO ()
main = do
  _ <- getArgsAndInitialize
  renderString Roman "test" -- Fails with: freeglut (myfile.hs): stroke font 0x404f0b20 not found
  mainLoop

Does it work for you?

Ooops, good point, I should have taken a closer look at my own example... ;-) With GHC 7.6.3, things work both interpreted and compiled on Windows (7, 64 bit, but this won't make a difference), and compiled on Linux x86_64. But I can reproduce the failure with a slightly modified Stroke.hs (drawing via 'renderString Roman' in the display callback). Nevertheless my guess about the reason still holds, I'll take a look in the next few days, but I wouldn't mind if somebody with more up-to-date knowledge about GHCi's linking/threading helps in the meantime. :-)

Just nitpicking: There is no such thing as "OpenGL fonts", GLUT is using basically the same technique as the example (drawing LineStrips), but doesn't even do it via display lists, see http://sourceforge.net/p/freeglut/code/HEAD/tree/trunk/freeglut/freeglut/src/fg_font.c. What makes Windows different is that it basically uses integers as names for fonts, while other platforms use opaque pointers, see http://sourceforge.net/p/freeglut/code/HEAD/tree/trunk/freeglut/freeglut/include/GL/freeglut_std.h. DLL legacy is beautiful... :-P

Well, this is issue already a bit old, but I'm just browsing through old issues, trying to clean things up...

I tried to reproduce this with GHC 7.8.3 on Linux x86_64, but I'm unable to trigger the error. I even installed gloss to see if I could see any problems with their gloss-examples/picture/Hello example (mentioned above), but again everything worked, so I need some help. Can you still reproduce the? If yes, how exactly?

nh2 commented

I'm a bit lost: When I run

import Graphics.UI.GLUT

main :: IO ()
main = do
  putStrLn "initializing"
  _ <- getArgsAndInitialize
  putStrLn "initialized"
  renderString Roman "test"
  putStrLn "before mainLoop"
  mainLoop
  putStrLn "mainLoop returned"

with runhaskell, I just get:

initializing
initialized
before mainLoop

and then my program exits with exit code 0.

Is that what should happen?

Anyway, I don't get the stroke font 0x45f37b20 not found error any more with the above code, runghc 7.8.4, and

ObjectName-1.1.0.0
OpenGLRaw-2.5.0.0
GLURaw-1.5.0.1
StateVar-1.1.0.0
OpenGL-2.12.0.1
GLUT-2.7.0.1

Regarding your example above: Yes, that's the normal GLUT behavior. You don't have any windows, so GLUT's main loop immediately considers its work done. What "done" in this case actually means can be controlled if you use freeglut, see actionOnWindowClose. So if you add

actionOnWindowClose $= MainLoopReturns

or

actionOnWindowClose $= ContinueExecution

before the mainLoop call, you would see the "mainLoop returned". The default action is calling exit(0) immediately, which is why the last putStrLn is not executed. The only thing which is slightly confusing is the fact that GLUT doesn't distinguish between having no window at all and closing the last window, but IMHO that's consistent.

Regarding the font problem: I think it's OK to close this issue because we have no repro, feel free to re-open if it occurs again somehow.

nh2 commented

Yes, seems good to close! Thank you! Also thanks for the explanation.