Page 1 of 1
#PB_Sprite_AlphaBlending and TIFF
Posted: Tue May 16, 2006 1:21 am
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.
If remove comments from "UseTIFFImageDecoder()" then create Error:
I use Win XP SP2.
Posted: Tue May 16, 2006 1:35 am
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.
Posted: Tue May 16, 2006 2:58 am
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,
you could set an example loadings sprite with AlphaChannel?
Posted: Tue May 16, 2006 3:18 am
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.)