Author Topic: [SOLVED] Transparency issues  (Read 5458 times)

0 Members and 1 Guest are viewing this topic.

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
[SOLVED] Transparency issues
« on: November 07, 2015 »
Hey guy`s, I`m having an awful time trying to get a image that has transparency to display correctly
it should display with a  semi transparent edge, but instead it gets cut off horribly
this is my code and ill include a picture
Ive tried different things, like using
Code: [Select]
Loadsprite(#PB,Any,"sun.png",#PB_Sprite_AlphaBlendingbut so far i haven't solved the problem, the effect I'm going for is like Mr Vain  used in his Reflections demo, with the lights on the police car flashing, the background was clearly visible.

Code: [Select]
InitSprite()
UsePNGImageDecoder()
InitKeyboard() 
OpenScreen(800,600,32,"PBWINDOW")
sun = LoadSprite(#PB_Any,"sun.png")
TransparentSpriteColor(sun,#White)
Repeat
ClearScreen($0)
ExamineKeyboard()
DisplayTransparentSprite(sun,0,0)
FlipBuffers()
Until KeyboardPushed (#PB_Key_Escape)
End
« Last Edit: November 07, 2015 by Omnikam »

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
Re: Transparency issues
« Reply #1 on: November 07, 2015 »
Okay Ive found a workaround, I'm not happy with it because it uses a Imagegadget and forces me to use OpenWindow instead of Openscreen
I guess the real issue is that i dont know how i can manipulate the image using imageGadget and still use openScreen and my sprites??

Code: [Select]
UseJPEGImageDecoder()
UsePNGImageDecoder()
OpenWindow(0, 0, 0, 800, 600, "TransTest", #PB_Window_SystemMenu | #PB_Window_ScreenCentered      )
 LoadImage(1, "c64startupscreen.jpg")
 LoadImage(2,"sun.png")
 CreateImage(0, 800, 600)
 StartDrawing(ImageOutput(0))
 DrawImage(ImageID(1), 0, 0, 800,600)
 DrawAlphaImage(ImageID(2), 100, 300,200)
 DrawingMode(#PB_2DDrawing_AlphaBlend)
 StopDrawing()
 ImageGadget(0, 0, 0, 800, 600, ImageID(0))
 Repeat
 Event = WaitWindowEvent()
 Until Event = #PB_Event_CloseWindow
« Last Edit: November 07, 2015 by Omnikam »

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
Re: Transparency issues
« Reply #2 on: November 07, 2015 »
I think Ive worked it out as follows
Code: [Select]
UseJPEGImageDecoder()
UsePNGImageDecoder()
InitSprite()
xres=800
yres=600
InitKeyboard()

window= OpenScreen(xres,yres,32,"(C) Omnikam 2015")
LoadImage(1, "c64startupscreen.jpg")
 LoadImage(2,"sun.png")
 CreateImage(0, 800, 600)
 StartDrawing(ScreenOutput())
 DrawImage(ImageID(1), 0, 0, 800,600)
 DrawAlphaImage(ImageID(2), 100, 300,200)
 DrawingMode(#PB_2DDrawing_AlphaBlend)
 StopDrawing()
 FlipBuffers()
 Repeat
 ExamineKeyboard()

Until KeyboardPushed (#PB_Key_Escape)
My question though is. How can i alter the values of for instance, the Draw AlphaImage in real time. So i can change transparency or move the image around?? I'm not sure as to how this is done

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
Re: Transparency issues
« Reply #3 on: November 07, 2015 »
Okay I did it myself  :updance:
I`m going to call it SOLVED, unless you can see a better way?
Or perhaps I'm doing something less efficient?
Okay i spoke too soon. It works for a time, but after maybe 7 seconds i get major slowdown, the image stops its fast strobe and slows down to a craw, does anyone know why this might happen? anyway to clear memory
Code: [Select]
UseJPEGImageDecoder()
UsePNGImageDecoder()
InitSprite()
xres=800
yres=600
InitKeyboard()
a=0
moveflag = 0
window= OpenScreen(xres,yres,32,"(C) Omnikam 2015")
LoadImage(1, "c64startupscreen.jpg")
LoadImage(2,"sun.png")
 Repeat
 CreateImage(0, 800, 600)
 StartDrawing(ScreenOutput())
 DrawImage(ImageID(1), 0, 0, 800,600)
 DrawAlphaImage(ImageID(2), 100, 300,a)
 DrawingMode(#PB_2DDrawing_AlphaBlend)
 StopDrawing()
 FlipBuffers()
If moveflag=0
    a=a+4
 
    If a>254
        moveflag = 1
    EndIf
 
EndIf

If moveflag=1
   a=a-4
    If a< 10
        moveflag = 0
      EndIf
    EndIf
 ExamineKeyboard()

Until KeyboardPushed (#PB_Key_Escape)
« Last Edit: November 07, 2015 by Omnikam »

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: [SOLVED] Transparency issues
« Reply #4 on: November 07, 2015 »
IF you want make the code looking much tidy and readable :)

Code: [Select]
; Quick way of putting all the code in Procedure
; When you start next project and you copy and paste
; Procedure _Startup() then You can code code much quicker!

; Dont forget put Global For a otherwise it wouldnt work!
Global a

Procedure _Startup()
     
      UsePNGImageDecoder()
      InitSprite()
      xres=800
      yres=600
      InitKeyboard()
      a=0
      moveflag = 0
      window= OpenScreen(xres,yres,32,"(C) Omnikam 2015")
      LoadImage(1, "c64startupscreen.png")
      LoadImage(2,"sun.png")

EndProcedure
   
Procedure Fader()
        If moveflag=0
        a=a+4
        If a>254
           moveflag = 1
        EndIf
     EndIf

     If moveflag=1
        a=a-4
        If a< 10
           moveflag = 0
        EndIf
      EndIf
EndProcedure
   
Procedure Draw_All()
       CreateImage(0, 800, 600)
       StartDrawing(ScreenOutput())
              DrawImage(ImageID(1), 0, 0, 800,600)
              DrawAlphaImage(ImageID(2), 100, 300,a)
              DrawingMode(#PB_2DDrawing_AlphaBlend)
       StopDrawing()
EndProcedure
         

_Startup()

Repeat
      Draw_All()
      FlipBuffers()
     
      Fader()
 
     ExamineKeyboard()
Until KeyboardPushed (#PB_Key_Escape)

Keep going and you are doing well  :clap:
« Last Edit: November 07, 2015 by Hotshot »

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
Re: [SOLVED] Transparency issues
« Reply #5 on: November 07, 2015 »
 :goodpost:
                 Thanks Hotshot, I never used Procedures So that was a very usefull post. Do you know why the strobing becomes slow? I read somewhere that it`s because i have the startdrawing and stopdrawing in a loop, but that doesn't make sense to me, as I've seen other code with them in a loop?? stumped
karma for your time hotshot  ;)
Ps Added Global moveflag  ;D
« Last Edit: November 08, 2015 by Omnikam »

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
Re: [SOLVED] Transparency issues
« Reply #6 on: November 08, 2015 »
 :carrot:   Ive finally done it  :clap:
Turns out for me, that using the startdrawing command suck`s. It So slow
The solution, Build a Sprite from an image, retaining the Alpha. The benefit being that rendering sprites in loops are fast
Credit`s to netmaestro from Purebasic forum for his BuildSprite() procedure  ;D
Added the exe`s so you can compare the 2 different codes, the Sprite animated one is fast, Draw too slow to be useful
Code: [Select]
Global a
Global moveflag
Global c64
Procedure BuildSprite(Sprite,Image,mode)

   Protected ImageID=ImageID(Image)

   w=ImageWidth(image)
   h=ImageHeight(image)
   
   CreateSprite(Sprite,w,h,mode)
   StartDrawing(SpriteOutput(Sprite))
     *buf = DrawingBuffer()
     If DrawingBufferPixelFormat() = #PB_PixelFormat_32Bits_BGR
       GetObject_(ImageID, SizeOf(BITMAP), bmp.BITMAP)
       If bmp\bmBitsPixel = 32
         CopyMemory(bmp\bmBits, *buf, w*h*SizeOf(RGBQUAD))
       EndIf
     EndIf
   StopDrawing()

 EndProcedure

Procedure _Startup()
  UsePNGImageDecoder()
  UseJPEGImageDecoder()
      InitSprite()
      xres=800
      yres=600
      InitKeyboard()
      a=0
      moveflag = 0
      windows=  OpenScreen(xres,yres,32,"(C) Omnikam 2015")
      LoadImage(sun,"sun.png")
      c64 =  LoadSprite(#PB_Any, "c64.jpg")
      BuildSprite(sun,ball,#PB_Sprite_AlphaBlending)
    EndProcedure
    Procedure Fader()
        If moveflag=0
        a=a+10
        If a>254
           moveflag = 1
        EndIf
     EndIf
     If moveflag=1
        a=a-10
        If a< 10
           moveflag = 0
        EndIf
      EndIf
    EndProcedure
    Procedure Draw_All()
   
    DisplaySprite(c64,0,0)
    ;ZoomSprite(c64,800,600)
    ;RotateSprite(sun,a,#PB_Relative)
    DisplayTransparentSprite(sun,300,a,a)
    EndProcedure
    _Startup()
   
   
    Repeat 
    Draw_All()
    FlipBuffers()
    Fader()

 ExamineKeyboard()
 Until KeyboardPushed (#PB_Key_Escape)
« Last Edit: November 08, 2015 by Omnikam »

Offline ~Ar-S~

  • C= 64
  • **
  • Posts: 61
  • Karma: 26
  • Demo RuleZ
    • View Profile
Re: [SOLVED] Transparency issues
« Reply #7 on: November 11, 2015 »
Hi, that's strange, i don't see any differences between buildsprite frome netmaestro and a classic drawing sprite.

Code: [Select]
Global a
Global moveflag
Global c64


Procedure _Startup()
  UsePNGImageDecoder()
  UseJPEGImageDecoder()
      InitSprite()
      xres=800
      yres=600
      InitKeyboard()
      a=0
      moveflag = 0
      windows=  OpenScreen(xres,yres,32,"(C) Omnikam 2015")
      LoadImage(sun,"sun.png")
      c64 =  LoadSprite(#PB_Any, "c64.jpg")
;       BuildSprite(sun,ball,#PB_Sprite_AlphaBlending)
      LoadSprite(sun,"sun.png",#PB_Sprite_AlphaBlending) ; <= why don't you use that ?
    EndProcedure
    Procedure Fader()
        If moveflag=0
        a=a+10
        If a>254
           moveflag = 1
        EndIf
     EndIf
     If moveflag=1
        a=a-10
        If a< 10
           moveflag = 0
        EndIf
      EndIf
    EndProcedure
    Procedure Draw_All()
   
    DisplaySprite(c64,0,0)
    ;ZoomSprite(c64,800,600)
    ;RotateSprite(sun,a,#PB_Relative)
    DisplayTransparentSprite(sun,300,a,a)
    EndProcedure
    _Startup()
   
   
    Repeat 
    Draw_All()
    FlipBuffers()
    Fader()

 ExamineKeyboard()
 Until KeyboardPushed (#PB_Key_Escape)
~ Ar-S ~

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 4
    • View Profile
Re: [SOLVED] Transparency issues
« Reply #8 on: November 11, 2015 »
If you downloaded the 2 included files, play the drawsprite, after 7-10 sec, could be longer on some computers, it will slow down nd the animation will stutter. Using build sprite fixed the problem, as did clipsprite