Page 1 of 1

Texture colors inverted in Linux/Windows

Posted: Sat Jun 25, 2022 2:48 pm
by Saboteur
I have a problem with 3dengine. I'm trying to create a texture with basic colors, but looks like colors are inverted, a Red in Windows, is Blue in Linux.
I'm not sure if it's a bug in engine, texture format, unknown driver's issue or whatever.

Some purebasic demos use differents ways to draw textures, setting the color with RGB(10,10,10) or directly $0A0A0A (but this would must not be the same). If I draw a image in Linux, the color is ok, so is possible this error only happens with engine3d (or textures).

There is a comment in the lines where texture is drawed, I don't see the error.

Can anyone check if Windows and Linux show the same colors?

Code: Select all

If(InitEngine3D())
  InitSprite()
  InitKeyboard()
  InitMouse()
  If(OpenWindow(0,0,0,1024,600,"Demo",#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)<>0)
    If(OpenWindowedScreen(WindowID(0),0,0,1024,600))
      AmbientColor(RGB(128,128,128))
      CreateCube(0,100)
      CreateTexture(0,128,128)
      If(StartDrawing(TextureOutput(0)))
        Box(0,0,64,128,RGB($FF,0,0))    ;  <------------------- Color 1 (Red)
        Box(64,0,64,128,$FF0000)        ;  <------------------- Color 2 (?)
        StopDrawing()
      EndIf
      CreateMaterial(0,TextureID(0))
      CreateEntity(0, MeshID(0), MaterialID(0))
      
      CreateCamera(0, 0, 0, 100, 100)
      CameraBackColor(0,$A0A0A0)
      MoveCamera(0,0,250,500,#PB_Absolute)
      CameraLookAt(0,0,0,0)
      CreateLight(0,RGB(255,255,255),0,250,500,#PB_Light_Point)
    Else
      End
    EndIf
  Else
    End
  EndIf
Else
  End
EndIf

Define.i done=0
Repeat
  Repeat
    event=WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        done=1
    EndSelect
  Until(event=0)
  Delay(10)
  
  RenderWorld()
  FlipBuffers()
Until done
This is what I get.
WINDOWS (Win 10, Nvidia GTX 1050Ti)
Image
LINUX (Ubuntu 20.04, Intel UHD)
Image

Re: Texture colors inverted in Linux/Windows

Posted: Sat Jun 25, 2022 9:32 pm
by idle
That's always been the case use rgb or rgba functions to define colors or use a bswap macro will post example when at computer

Re: Texture colors inverted in Linux/Windows

Posted: Sun Jun 26, 2022 11:26 am
by Saboteur
But the operation should give the same result in both Windows and Linux, right?

Re: Texture colors inverted in Linux/Windows

Posted: Sun Jun 26, 2022 9:01 pm
by idle
You would only need to swap on one os and it also depends on your pixel format. Just define your colors with rgb or rgba functions and there's no problem.

Re: Texture colors inverted in Linux/Windows

Posted: Mon Jun 27, 2022 3:12 am
by idle
If you don't want to use RGB or RGBA functions and your bit depth is 32 then you can use this bswap32 macro
this works for longs only.

Code: Select all

Macro _Bswap32(var) ; var.l only fasm 
 CompilerIf #PB_Compiler_OS <> #PB_OS_Windows    
  CompilerIf #PB_Compiler_Backend = #PB_Backend_C  
    !v_#var = __builtin_bswap32(v_#var); 
  CompilerElse 
    EnableASM 
    mov eax,var 
    bswap eax 
    mov var,eax 
    DisableASM 
  CompilerEndIf 
 CompilerEndIf 
EndMacro   
    
Global col.l = $00AA00FF 
Debug col 
_bswap32(col) 
Debug col  



Re: Texture colors inverted in Linux/Windows

Posted: Mon Jun 27, 2022 9:58 am
by Saboteur
Thank you. I don't have problems swapping bytes, but it's confusing some purebasic functions give different results on different computers.
I think RGB($FF,0,0) would must be red on windows and linux.