Page 1 of 1

PNG Decoder reads RGBA(0,0,0,$FF) as 0

Posted: Tue Nov 10, 2009 1:54 pm
by Deeem2031

Code: Select all

InitSprite()
InitSprite3D()
OpenWindowedScreen(OpenWindow(0,0,0,800,600,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered), 0,0,800,600,0,0,0)

UsePNGImageDecoder()
LoadSprite(0, "bg_00.png", #PB_Sprite_Texture)
CreateSprite3D(0, 0)
LoadSprite(1, "bg_01.png", #PB_Sprite_Texture)
CreateSprite3D(1, 1)

ZoomSprite3D(0, 800, 600)
ZoomSprite3D(1, 800, 600)
Repeat
  
  Start3D()
  DisplaySprite3D(1, 0, 0)
  DisplaySprite3D(0, 0, 0)
  Stop3D()
  FlipBuffers()
    
  Select WindowEvent()
    Case #PB_Event_CloseWindow
      quit = #True
  EndSelect
Until quit
bg_00.png: http://www.deeem2031.de/PB/bg_00.png
bg_01.png: http://www.deeem2031.de/PB/bg_01.png

The result:

Image

As you can see there are yellow pixels even thought the second DisplaySprite3D() should cover the whole screen. My guess is that the png decoder decodes the pixels with a RGBA(0,0,0,$FF) value as RGBA(0,0,0,0).

P.S.: Or DisplaySprite3D somehow interprets RGBA(0,0,0,$FF) as RGBA(0,0,0,0)

Re: [4.40b6x86] PNG Decoder reads RGBA(0,0,0,$FF) as 0

Posted: Tue Nov 10, 2009 4:57 pm
by c4s
[OFFTOPIC]
Is this a screenshot from Conspiracy's "Beyond"?
...Oh I love this demo!
[/OFFTOPIC]

Re: [4.40b6x86] PNG Decoder reads RGBA(0,0,0,$FF) as 0

Posted: Tue Nov 10, 2009 6:01 pm
by Deeem2031
c4s wrote:[OFFTOPIC]
Is this a screenshot from Conspiracy's "Beyond"?
...Oh I love this demo!
[/OFFTOPIC]
Yes. (The next version of eirstt will use screenshots of this demo as background images.)

Re: [4.40b6x86] PNG Decoder reads RGBA(0,0,0,$FF) as 0

Posted: Thu Dec 10, 2009 9:38 pm
by Fred
By default, PB use the 0,0,0 color as transparent (can be changed with TransparentSpriteColor()), unless you speficy otherwise. To use the 32 bits alpha channel info instead, you need to use the '#PB_Sprite_AlphaBlending' flag:

Code: Select all

InitSprite()
InitSprite3D()
OpenWindowedScreen(OpenWindow(0,0,0,800,600,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered), 0,0,800,600,0,0,0)

UsePNGImageDecoder()
LoadSprite(0, "bg_00.png", #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CreateSprite3D(0, 0)
LoadSprite(1, "bg_01.png", #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CreateSprite3D(1, 1)

ZoomSprite3D(0, 800, 600)
ZoomSprite3D(1, 800, 600)
Repeat
 
  Start3D()
  DisplaySprite3D(1, 0, 0)
  DisplaySprite3D(0, 0, 0)
  Stop3D()
  FlipBuffers()
   
  Select WindowEvent()
    Case #PB_Event_CloseWindow
      quit = #True
  EndSelect
Until quit