[Solved] PB 5.20 - opaque sprite (alphablending)

Just starting out? Need help? Post your questions and find answers here.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

[Solved] PB 5.20 - opaque sprite (alphablending)

Post by eddy »

Hi,
I updated this sprite test but I don't know why my sprite is opaque now.
[solved]

Code: Select all

DisableExplicit

UsePNGImageEncoder()
UsePNGImageDecoder()

InitSprite()


win=OpenWindow(#PB_Any, 0, 0, 610, 410, "PB 5.20b - Sprite alphablending",
               #PB_Window_SystemMenu |
               #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(win), 5, 5, 600, 400, 0, 0, 0, #PB_Screen_NoSynchronization)

img=CreateImage(#PB_Any, 200, 200, 32, #PB_Image_Transparent) ;<---- sprite source image is transparent
If StartDrawing(ImageOutput(img))
   DrawingMode(#PB_2DDrawing_Gradient|
               #PB_2DDrawing_AlphaBlend|
               #PB_2DDrawing_Transparent)
   BackColor(RGBA(255, 255, 255, 255))
   GradientColor(0.3, RGBA(255, 100, 0, 100))
   FrontColor(RGBA(255, 0, 0, 0))
   CircularGradient(150, 100, 100)
   Circle(100, 100, 100)
   StopDrawing()
   
   *imgMemory=EncodeImage(img, #PB_ImagePlugin_PNG, 10, 32)
   If *imgMemory
      flare=CatchSprite(#PB_Any, *imgMemory, #PB_Sprite_AlphaBlending) ;<---- enable alphablending
      flare2=CopySprite(flare, #PB_Any, #PB_Sprite_AlphaBlending)
   EndIf
EndIf

Repeat   
   ClearScreen(#Black)   
   
   RotateSprite(flare, 0.1, #PB_Relative)
   DisplayTransparentSprite(flare, 200, 100) ;<---- draw sprite with alphablending
   
   RotateSprite(flare2, 0.1, #PB_Relative)
   DisplayTransparentSprite(flare2, 50, 50)
   
   FlipBuffers()   
      
Until WindowEvent()=#PB_Event_CloseWindow
Last edited by eddy on Sat Jun 22, 2013 12:35 am, edited 4 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 5.20 - opaque sprite

Post by Fred »

You need to use DisplayTransparentSprite()
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: PB 5.20 - opaque sprite

Post by eddy »

img=CreateImage(#PB_Any, 200, 200, 32|#PB_Image_Transparent)
The source image of my sprite is opaque because this code above is not supported.
#PB_Image_Transparent flag usage has been modified.
Last edited by eddy on Sat Jun 22, 2013 12:37 am, edited 4 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 5.20 - opaque sprite

Post by Fred »

img=CreateImage(#PB_Any, 200, 200, 32, #PB_Image_Transparent)
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: PB 5.20 - opaque sprite

Post by eddy »

Fred wrote:img=CreateImage(#PB_Any, 200, 200, 32, #PB_Image_Transparent)
I see.

I tested this code but it does not work.
Image
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 5.20 - opaque sprite

Post by Fred »

you need DisplayTransparentSprite() to correctly display alphablended sprites
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: [Solved] PB 5.20 - opaque sprite

Post by eddy »

Thx, it works
I updated the code above

Image
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Re: [Solved] PB 5.20 - opaque sprite (alphablending)

Post by [blendman] »

Hi

your code doesn't work on win8 with pb5.2b. I don't have any transparence.
It works with pb5.11 (with a little change)
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: [Solved] PB 5.20 - opaque sprite (alphablending)

Post by em_uk »

Doesn't work here with Win7 5.2b x86.

All I get is :

Image
----

R Tape loading error, 0:1
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: [Solved] PB 5.20 - opaque sprite (alphablending)

Post by eddy »

report this bug if you have no transparency in PB beta4
What GPU do you have ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: [Solved] PB 5.20 - opaque sprite (alphablending)

Post by ricardo »

Using this code:

Code: Select all

img=CreateImage(#PB_Any, 200, 200, 32, #PB_Image_Transparent) ;<---- sprite source image is transparent
If StartDrawing(ImageOutput(img))
    DrawingMode(#PB_2DDrawing_Gradient|
    #PB_2DDrawing_AlphaBlend|
    #PB_2DDrawing_Transparent)
    BackColor(RGBA(100, 255, 255, 255))
    GradientColor(0.3, RGBA(255, 100, 0, 255))
    FrontColor(RGBA(255, 100, 0, 255))
    CircularGradient(150, 100, 100)
    Circle(100, 100, 100)
  StopDrawing()
  
  *imgMemory=EncodeImage(img, #PB_ImagePlugin_PNG, 10, 32)
  If *imgMemory
  flare=CatchSprite(#PB_Any, *imgMemory, #PB_Sprite_AlphaBlending) ;<---- enable alphablending
  flare2=CopySprite(flare, #PB_Any, #PB_Sprite_AlphaBlending)
EndIf
EndIf

I m getting this
Image

But i want to make it much brilliant, with more light. Im very new in drawing and all this, thats why i am making this naive question.

Please advice.
ARGENTINA WORLD CHAMPION
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Solved] PB 5.20 - opaque sprite (alphablending)

Post by mk-soft »

Over four jears to late :mrgreen:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply