首页 > 解决方案 > 需要 renderString 解释

问题描述

我使用 GLUT 在 Haskell 中编写显示回调

这是开始:

display :: IORef Float  -> IORef [(GLfloat , GLfloat ,GLfloat )] -> IORef Akkord-> DisplayCallback
display remain colors gespielt= do

  clear [ ColorBuffer ]

  renderPrimitive Quads $ do 
    --lots of things are rendered 

最后,我试图显示一种分数(gespielt):

  g <- get gespielt
  color3f 0 0 0
  preservingMatrix $ do
    renderString Fixed9By15  "Hallo"
    

  flush

“你好”将被替换为 (Show g)

但结果是一样的,没有任何文字显示在任何地方

没有编译错误,我尝试更改颜色并缩放文本

我从 haskell.org OpenGLTutorial 偷了这个:

color3f :: GLfloat -> GLfloat -> GLfloat -> IO ()
color3f r g b = color $ Color3 r g (b :: GLfloat)

我在这里做错了什么?

标签: haskellopenglglut

解决方案


我从这里使用了一种解决方法:如何在 Glut - Fungen - Haskell 中使用其他字体

putGameText [] = return ()
putGameText ((text,font ,(x,y), r,g,b):ts) = do 
  loadIdentity 
  color (Color3 r g (b :: GLfloat))
  rasterPos (Vertex2 x (y :: GLfloat))
  renderString font text
  putGameText ts

我假设 renderString 需要首先调用 rasterPos 或类似的


推荐阅读