我如何在 Glut - Fungen - Haskell 中使用其他字体

发布于 2024-12-16 21:33:57 字数 336 浏览 4 评论 0原文

我正在使用 Haskell 的 Fungen 框架,并且有一个使用 BitmapFonts 的函数。问题是,我唯一可以使用的 BitmapFont 是 GLUT 附带的 BitmapFont,这里是数据:

data BitmapFont =固定8By13 |固定9By15 |时代罗马10 |时代罗马24 |黑体10 |黑体12 | Helvetica18

这些字体对于我的应用程序来说非常小,我想使用另一种 BitmapFont,而不仅仅是这些,或者使其中一个更大。我该怎么做呢?

I'm using the Fungen framework for Haskell and there is a function that uses BitmapFonts. The thing is, that the only BitmapFonts I can use are the ones that come with GLUT, here is the data:

data BitmapFont
= Fixed8By13
| Fixed9By15
| TimesRoman10
| TimesRoman24
| Helvetica10
| Helvetica12
| Helvetica18

These fonts are very small for my application, and I want to use another BitmapFont, not just these, or make one of these bigger. How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煮茶煮酒煮时光 2024-12-23 21:33:57

这是 putGameText

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

据我了解,FunGENn 的 Text 类型将字体限制为固定大小 BitMapFont

type Text = (String, BitmapFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)

但 renderString 可以还取一个StrokeFont ,其字体系列受到更多限制,但响应标准 OpenGL 缩放/变换/旋转

因此,一个好的开始可能是让 myPutGameText 接受支持 StrokeFont 的 MyText 并在渲染之前进行缩放变换。这是一些伪代码,我希望有人能纠正:

type MyText = (String, StrokeFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)

myPutGameText :: [MyText] -> (GLDouble,GLDouble,GLDouble) -> IO ()
myPutGameText [] _ = return ()
myPutGameText ((text,font,(x,y),r,g,b):ts) (sx,sy,sz) = do
    loadIdentity
    preservingMatrix $ do
      scale sx sy sz
      color (Color3 r g b)
      rasterPos (Vertex2 x y)
      renderString font text
      putGameText ts

为了更丰富的字体渲染,答案可能是集成类似 的内容FTGL

Here's the source of putGameText:

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

As I understand it, FunGEn's Text type constrains font to a fixed-size BitMapFont:

type Text = (String, BitmapFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)

but renderString can also take a StrokeFont, which is even more limited in font family but responds to standard OpenGL scaling/transformation/rotation.

So, a good start might be to make myPutGameText that accepts a StrokeFont-capable MyText and does a scaling transform before rendering. Here's some pseudo-code which I hope someone will correct:

type MyText = (String, StrokeFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)

myPutGameText :: [MyText] -> (GLDouble,GLDouble,GLDouble) -> IO ()
myPutGameText [] _ = return ()
myPutGameText ((text,font,(x,y),r,g,b):ts) (sx,sy,sz) = do
    loadIdentity
    preservingMatrix $ do
      scale sx sy sz
      color (Color3 r g b)
      rasterPos (Vertex2 x y)
      renderString font text
      putGameText ts

For richer font rendering, the answer is probably to integrate something like FTGL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文