#PB_Sprite_AlphaBlending and TIFF

Just starting out? Need help? Post your questions and find answers here.
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

#PB_Sprite_AlphaBlending and TIFF

Post by newart »

Code: Select all

UsePNGImageDecoder()
;UseTIFFImageDecoder() 

#frate = 100
#scrw = 800                              
#scrh = 600                               
#scrd = 32


If InitSprite() = 0 Or InitSprite3D() = 0 Or  InitKeyboard() = 0 Or InitMouse()=0:MessageRequester("Error", "Can't open DirectX 7 Or later", 0):End:EndIf


If OpenScreen(#scrw, #scrh, #scrd, "Test")
  SetFrameRate(#frate)

  
LoadSprite (0, "cursor2.png", #PB_Sprite_AlphaBlending)
TransparentSpriteColor(0,0)

Repeat
FlipBuffers(1): ExamineKeyboard(): ExamineMouse()
ClearScreen(RGB(224,200,190))

msx=MouseX()
msy=MouseY()

DisplayTransparentSprite(0, msx, msy)


Until KeyboardPushed(#PB_Key_Escape)
EndIf
End
Sprite output without Alpha. :(

Image

If remove comments from "UseTIFFImageDecoder()" then create Error:

Image


I use Win XP SP2.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

#PB_Sprite_AlphaBlending goes together with #PB_Sprite_Texture at the time of creation for a 2D sprite which will in turn be used to create a 3D sprite, which will then show alpha transparency correctly. No transparent SpriteColor is needed. You must use a 3D sprite to get the correct alpha rendering, as a 2D sprite won't do it.

As to why the linker is getting the error, that file should be found in your PureBasic installation. If it is not, you'll need to repair or reinstall your PB.
BERESHEIT
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

Post by newart »

netmaestro wrote:#PB_Sprite_AlphaBlending goes together with #PB_Sprite_Texture at the time of creation for a 2D sprite which will in turn be used to create a 3D sprite, which will then show alpha transparency correctly. No transparent SpriteColor is needed. You must use a 3D sprite to get the correct alpha rendering, as a 2D sprite won't do it.

As to why the linker is getting the error, that file should be found in your PureBasic installation. If it is not, you'll need to repair or reinstall your PB.
Thanks.
But I have not absolutely understood, :oops:
you could set an example loadings sprite with AlphaChannel?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You need this PNG image: http://www.networkmaestro.com/stefan_full_rgba.png

Make it available to this code snippet and see it display with alpha:

Code: Select all

InitSprite():InitSprite3D() 
UsePNGImageDecoder() 
OpenWindow(0,0,0,640,480,"AlphaChannel Sprite",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0) 
LoadSprite(0, "stefan_full_rgba.png",#PB_Sprite_Texture|#PB_Sprite_AlphaBlending) 
CreateSprite3D(0,0) 
Sprite3DQuality(1)
Repeat 
  ClearScreen(#White) 
  Start3D() 
    TransformSprite3D(0,0,0,100,0,500,500,0,250) ; Just to have a little fun!
    DisplaySprite3D(0,200,100) 
  Stop3D() 
  StartDrawing(ScreenOutput())
    DrawText(160,130,"AWK!!",#Red,#White)
  StopDrawing()
  FlipBuffers() 
Until WaitWindowEvent(1) = #WM_CLOSE 
When you're working with the 2DDrawing library, you have to specify DrawAlphaImage() if you want to display the alpha layer, and DrawImage() if it isn't needed. For sprites, there is no separate command. DisplaySprite3D() will automatically display correct alphas if the AlphaBlending flag was included with the Texture flag on creation of the original 2D sprite. (that the 3D sprite was created from.)
BERESHEIT
Post Reply