haskell - 为什么这条 Haskell SDL 线应该是白色的却是青色?

标签 haskell sdl

下面是一些使用 SDL 和 Haskell 绘制对角线的代码。当 RGB 明显应该是白色时,我得到一条青色线。这是在 Ubuntu 上。难道我做错了什么?

import qualified Graphics.UI.SDL as SDL
import qualified Graphics.UI.SDL.Primitives as SDLP

main = do
    SDL.init [SDL.InitEverything]
    SDL.setVideoMode 640 480 32 []
    SDL.setCaption "My Window" "My Test"
    surf0 <- SDL.getVideoSurface
    white <- SDL.mapRGB (SDL.surfaceGetPixelFormat surf0) 255 255 255
    SDLP.line surf0 0 0 640 480 white 
    SDL.flip surf0
    eventLoop
    SDL.quit
    print "done"
    where
    eventLoop = SDL.waitEventBlocking >>= checkEvent
    checkEvent (SDL.KeyUp _) = return ()
    checkEvent _ = eventLoop

最佳答案

也许是一个不那么肮脏的黑客(尽管可能取决于平台/实现):

import GHC.Word
import Data.Bits

fi a = fromIntegral a

rgbColor::Word8→ Word8→ Word8→ Pixel
rgbColor r g b = Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255))

关于haskell - 为什么这条 Haskell SDL 线应该是白色的却是青色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3286864/

相关文章:

c++ - SDL2 : I Receive Segmentation Fault on Line 5, SDL_表面

haskell - Haskell 中的非确定性是什么?

haskell - 随机数生成器的最佳选择

c - 如何在 ST monad 中执行 FFI 调用

c++ - 处理曲面 vector 时如何正确使用 SDL_FreeSurface

c++ - 一个很好的 OO 方法来做到这一点 (c++)

C++ - 错误 LNK2001 : unresolved external symbol

twitter-bootstrap - Haskell 等式约束

haskell - "curl libraries?"在哪里

C++ union 赋值,有什么好办法吗?