在Haskell中使用OpenGL渲染PNG图像 [英] Render PNG images using OpenGL in Haskell

查看:149
本文介绍了在Haskell中使用OpenGL渲染PNG图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Haskell的新手,我正在使用 OpenGL (使用 Graphics.UI.GLUT )为UI。我试图为棋子呈现PNG图像。



我读过图像可以转换为 TextureObject 然后呈现,但找不到任何有用的资源,以知道如何做到这一点。



这就是我的代码生成棋盘的样子

  drawSquare :: BoardSquare  - > IO()
drawSquare((x,y,z),(r,g,b))= preservingMatrix $ do
color $ Color3 rgb
translate $ Vector3 xyz
drawCube - 这将绘制一个适当大小的正方形

- 显示回调
display :: IORef GameState - > DisplayCallback
display gameState = do
gstate< - get gameState
clear [ColorBuffer]
forM_(getBoardPoints gstate)$ drawSquare - 在这里绘制所有64个方格
flush

任何人都可以帮我渲染任何给定的 x y 给定文件路径的窗口坐标?

解决方案

建议:由于你是Haskell的新手,而不是直接进入你的国际象棋游戏的原始 OpenGL ,你看过图书馆帮助你让 OpenGL 更容易?我会推荐 gloss ,它看起来像 gloss-game 有一个助手函数 .png 文件加载到内存中准备好用于你的游戏。祝你好运! : - )

I am new to Haskell and I am building a chess game using OpenGL (using Graphics.UI.GLUT) for UI. I am trying to render PNG images for chess pieces.

I read that images can be converted to TextureObject and then rendered, but could not find any helpful resources to know how to do it.

This is what my code looks like for generating the chess board

drawSquare :: BoardSquare -> IO ()
drawSquare ((x,y,z),(r,g,b)) = preservingMatrix $ do
    color $ Color3 r g b
    translate $ Vector3 x y z
    drawCube -- this will draw a square of appropriate size

-- Display Callback
display :: IORef GameState -> DisplayCallback
display gameState = do
    gstate <- get gameState
    clear [ColorBuffer]
    forM_ (getBoardPoints gstate) $ drawSquare -- drawing all 64 squares here
    flush

Can anyone help me render PNG image at any given x and y coordinates of the window with given file path?

解决方案

Suggestion: Since you are new to Haskell, instead of diving straight into raw OpenGL for your chess game, have you looked at libraries that could help you make OpenGL easier? I would recommend gloss and it looks like gloss-game has a helper function to load a .png file into memory ready to be used for your game. Good luck! :-)

这篇关于在Haskell中使用OpenGL渲染PNG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆