Open POPSuL opened 4 years ago
Hi @POPSuL, I'll have a detailed look at it sometime today! I will comment again once I know what causes the issue.
@veeableful thanks! I'll wait. If additional information needed - I can inform.
Btw, I force set pixel format via
surface.Format.Format = sdl.PIXELFORMAT_RGB888
(before calling Surface.Set()) and now that sample works correctly, and in linux looks like in windows (both OS draws RED square).
Hi @POPSuL, it should have been fixed in the master branch now!
Though the following code is not working. It is showing a blue rectangle, on GNU/Linux, I haven't tested it on Windows.
package main
import (
"github.com/veandco/go-sdl2/sdl"
"golang.org/x/image/colornames"
)
func main() {
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
800, 600, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
defer window.Destroy()
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
surface.FillRect(nil, 0)
rect := sdl.Rect{0, 0, 200, 200}
surface.FillRect(&rect, sdl.Color(colornames.Red).Uint32())
window.UpdateSurface()
running := true
for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) {
case *sdl.QuitEvent:
println("Quit")
running = false
break
}
}
}
}
Hi @dev-abir! Unfortunately, the default pixel format used by the window surface is RGB888 which is incompatible with sdl.Color (RGBA8888).
You can work around this by creating another surface with matching pixel format and then blit it on to the window surface, like this:
...
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
surface.FillRect(nil, 0)
rgbaSurface, err := sdl.CreateRGBSurfaceWithFormat(0, surface.W, surface.H, 32, sdl.PIXELFORMAT_RGBA8888)
if err != nil {
panic(err)
}
rect := sdl.Rect{0, 0, 200, 200}
c := sdl.Color(colornames.Red).Uint32()
rgbaSurface.FillRect(&rect, uint32(c))
rgbaSurface.Blit(nil, surface, nil)
window.UpdateSurface()
...
Hi @dev-abir! Unfortunately, the default pixel format used by the window surface is RGB888 which is incompatible with sdl.Color (RGBA8888).
You can work around this by creating another surface with matching pixel format and then blit it on to the window surface, like this:
... surface, err := window.GetSurface() if err != nil { panic(err) } surface.FillRect(nil, 0) rgbaSurface, err := sdl.CreateRGBSurfaceWithFormat(0, surface.W, surface.H, 32, sdl.PIXELFORMAT_RGBA8888) if err != nil { panic(err) } rect := sdl.Rect{0, 0, 200, 200} c := sdl.Color(colornames.Red).Uint32() rgbaSurface.FillRect(&rect, uint32(c)) rgbaSurface.Blit(nil, surface, nil) window.UpdateSurface() ...
Okay thanks
Example code for drawing RED square:
Problem: Windows 10 draws RED square, but in Linux (Ubuntu, KDE) that code draws BLUE square. Due debugging I found difference between pixel format in surface (windows have RGB888 but linux have RGBA8888). If we look at the code of Surface.Set() we can found 2 branches:
And
First branch executes on linux and not working correctly. Second branch executes on windows and work correctly. But, first should have "SAME" logic (+alpha), but in first case we have RGBA to RGBA conversion and it possible not correctly for SDL2 and we have RGBA to BRG which possible correctly.