为什么 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
Below is some code to use SDL with Haskell to draw a diagonal line. I get a CYAN line when the RGB clearly should be white. This is on Ubuntu. Am I doing something wrong?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许是一个不太肮脏的黑客(尽管可能取决于平台/实现):
Maybe a less dirty hack (though probably platform/implementation dependant) :
我在使用 ATI HD2400 和 radeon 驱动程序的 Lucid 上观察到相同的效果(如果这很重要的话)。但有一个解决方法。
这个例子画了一条白线:
我承认这是一个丑陋的黑客,但似乎默认表面的像素格式不是RGB(?),并且使用已知为RGB的表面的像素格式会有所帮助。我没有使用 SDL 的经验,所以我无法判断正确的使用方法是什么。
I observe the same effect on Lucid with ATI HD2400 and radeon driver (if that matters). But there is a workaround.
This example draws a white line:
I accept that this is an ugly hack, but it seems that default surface' pixel format is not RGB (?), and using a pixel format of a surface known to be RGB helps. I don't have experience with SDL, so I cannot tell what the right way to use it is.
我在我的系统上遇到了同样的问题(对于线条和其他基元),并且直接使用
Pixel
构造函数而不是mapRGB
似乎给出了正确的颜色。例如,如果我将
Graphics.UI.SDL.Color
导入为SDLC
,然后letwhite' = SDLC.Pixel maxBound
,我会得到白线,正如预期的那样。使用SDLC.Pixel 4278190335
(或255 * 2^24 + 255
,一个合理的红色值),我得到一条红线。这显然不是真正的解决方案或答案,但它可能会建议一些起点。
另一件奇怪的事情是:如果我像这样打印你的白色和我的白色:
我得到这个:
所以它们通过 getRGBA 看起来相同,但实际的 Pixel 值不同。
I get the same issue on my system (for both lines and other primitives), and using the
Pixel
constructor directly instead ofmapRGB
seems to give the correct colors.For example, if I import
Graphics.UI.SDL.Color
asSDLC
and thenlet white' = SDLC.Pixel maxBound
, I get a white line, as expected. WithSDLC.Pixel 4278190335
(or255 * 2^24 + 255
, a sensible value for red), I get a red line.This clearly isn't a real solution or answer, but it might suggest some starting points.
One other odd thing: if I print both your white and mine like so:
I get this:
So they look the same via
getRGBA
, but the actualPixel
values are different.