這裏是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
據我瞭解,FunGEn的文本類型限制字體大小固定的BitMapFont:
type Text = (String, BitmapFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)
但renderString也可以採取StrokeFont,其中在字體系列中更受限制,但對標準OpenGL scaling/transformation/rotation作出響應。
所以,一個好的開始可能是讓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整合。
我已經將BitmapFont替換爲了改變FunGen代碼的StrokeFont,但是strokeFonts太大了!但我不知道我可以改變strokeFonts的大小,我會嘗試它並告訴你發生了什麼。感謝你的回答! –
我改變了strokeFont的大小,但做完之後,文本出現在屏幕的底部,我無法改變它的位置。那只是在改變尺寸後纔會發生。我決定在我的遊戲中使用固定的bitmapFont,因爲我沒有時間浪費字體。無論如何感謝您的答案 –