下面是一些使用 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/