AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.16k stars 128 forks source link

[bug] Color rendering issue with latest updates #715

Closed damntourists closed 8 months ago

damntourists commented 9 months ago

What happend?

It seems I can only render certain colors at the moment. The following example works for red, but not green or blue. I also tried with color.RGBA and color.NRGBA without any success. It seems when I zero out red and try to render green or blue, nothing renders at all, almost like alpha is turned to zero when it is not.

Code example

pseudo main.go ```golang [ ... ] for _, char := range w.chars { // testColor := g.UintToColor(0xFF0000FF) // c.RGBA{R: 255, G: 0, B: 0, A: 255} // works // testColor := g.UintToColor(0x00FF00FF) // c.RGBA{R: 0, G: 255, B: 0, A: 255} // doesn't work // testColor := g.UintToColor(0x0000FFFF) // c.RGBA{R: 0, G: 0, B: 255, A: 255} // doesn't work testColor := g.UintToColor(0x00FF00FF) // c.RGBA{R: 0, G: 255, B: 0, A: 255} charPos := pos.Add(image.Pt(int(char.X), int(char.Y))) // shadowPos := charPos.Add(image.Pt(1, 1)) // canvas.AddText(shadowPos, c.RGBA{R: 0, G: 0, B: 0, A: uint8(char.A)}, char.Value) canvas.AddText(charPos, testColor, char.Value) } [ ... ] ```

To Reproduce

  1. Run my demo
  2. will see the crash...

Version

master

OS

ubuntu

gucio321 commented 8 months ago

Conclusion: I had to mess up colors conversion Conclusion 2: unittests are useful... sometimes

gucio321 commented 8 months ago

After testing I found that there is something wrong with ColorToUint (UintToColor works fine)

gucio321 commented 8 months ago

ok, found it:

    return r&mask<<24 + g&mask<<16 + b&mask<<8 + a&mask

it is reversed