Transparency

Blitz3D Forums/Blitz3D Beginners Area/Transparency

In Blitz3D, is there a way to make a loaded image partially transparent?
Basicallly, I want to be able to fade in a logo by starting the image off completely transparent, and then reducing the transparency gradually.

Not sure how i'd accomplish this.

The best way is to use your image to texture a quad, then use EntityAlpha on the quad itself.

or use a fliped-black-box around your camera and use entityalpha on the blackbox ( yes, it seems to be the same way xD ) but it can extend to a transition Library that can be used for many things.

like this one
( using quad , and allow transition Fx, allow setting start color/end color for the transition, and a Cine Fx => Mode 16/9 )

;==============================================================================================
;==============================================================================================
;
;	Librairie d'effets simples => Fondu de camera, et effet Cinema ( 16/9 )
;	Par ®BOBYSAIT => <a href="http://www.BlitzFr.com" target="_blank">http://www.BlitzFr.com</a>
;	utilisation libre
;	=>la rstriction est de mentionner mon pseudo dans vos credits
;	=> et un lien vers le site blitzFr serait apprecié !
;
;	Avec transition, et choix des couleurs
;	Verification automatique de l'existence de chaque entité
;	pour s'assurer de ne pas avoir d'erreur de programme !
;	Optimiser au mieux pour le moment
;
;	Pour toutes info, mailez moi à Bobysait@... ou passez sur le site www.BlitzFr.Com !
;
;==============================================================================================
;==============================================================================================


; le type pour la fonction Cine
Type Fx_Cine
	Field Cam%
	Field Zoom#
	Field Sp%
	Field ColR%,ColG%,ColB%
	Field Etape%
End Type


; le type pour les fondu de camera
Type Fx_Fondu
	Field Cam%			;	camera du fondu
	Field Zoom#			;	zoom de la camera
	Field Sp%			;	Sprite du fondu
	Field Alpha#		;	niveau courant de l'alpha
	Field Time%			;	Durée du fondu
	Field FlipIt%		;	Fondu independant ou pendant une scene ?
	Field Mode%			;	Fondu In ou Out
	Field Etape%		;	stade du fondu ( actif, en attente etc... )

	Field S_ColR%		;	Couleurs RGB du debut de fondu
	Field S_ColG%
	Field S_ColB%

	Field E_ColR%		;	couleurs RGB finales du fondu
	Field E_ColG%
	Field E_ColB%
End Type



Function FX_Create_cinema3D(camera,Order_Fx2=-1,ColR%=0,ColG%=0,ColB%=0,Zoom#=1)
	If camera<>0
	fx.Fx_Cine	=	New Fx_Cine
		Fx\Cam%		=	Camera
		fx\Zoom#	=	Zoom
		Fx\ColR%	=	ColR
		Fx\ColG%	=	ColG
		Fx\ColB%	=	ColB
		fx\etape%	=	0		;	par defaut le mode est desactivé !

		Fx\Sp%		=	CreateMesh		(camera)
		Local sfc	=	CreateSurface	(Fx\Sp)
						AddVertex		sfc		,-8.2/8	,6.2/8	,0
		Local l_v%	=	AddVertex		(sfc	,8.2/8	,6.2/8	,0)
						AddVertex		sfc		,-8.2/8	,4.5/8	,0
						AddVertex		sfc		,8.2/8	,4.5/8	,0

						AddVertex		sfc		,-8.2/8	,-4.5/8	,0
						AddVertex		sfc		,8.2/8	,-4.5/8	,0
						AddVertex		sfc		,-8.2/8	,-6.2/8	,0
						AddVertex		sfc		,8.2/8	,-6.2/8	,0

						AddTriangle		sfc		,l_v+0	,l_v+1	,l_v+2
						AddTriangle		sfc		,l_v+3	,l_v+2	,l_v+1
						AddTriangle		sfc		,l_v+4	,l_v+5	,l_v+6
						AddTriangle		sfc		,l_v+7	,l_v+6	,l_v+5

						EntityColor		Fx\Sp	,ColR,ColG,ColB
						EntityOrder		Fx\Sp	,Order_Fx2
						MoveEntity		Fx\Sp	,0,0,Zoom
						NameEntity		Fx\Sp	,Handle(fx)
						HideEntity		Fx\Sp
    Return Fx\Sp
	Else
		Return False
	EndIf
End Function



Function Fx_MAJ_CINE(Cine%,NewIt%=True,camera%=0)
	If Cine=0
		Return False
	Else
		; à faire => bascule le mode cine On/OFF avec transition
		fx.Fx_Cine=Object.Fx_Cine(EntityName(Cine))
		If Fx<>Null
			Select fx\etape
				Case 1
					ShowEntity Fx\Sp
				Default
			End Select
		Else
			; pas de cine créé ?
			If NewIt=True And Camera<>0
				; => on en créé un nouveau, il sera mis à jour à la prochaine boucle !
				Cine	=	FX_Create_cinema3D(camera,-1,0,0,0,1)
				Return	Cine
			EndIf
		EndIf
	EndIf
End Function


Function FX_DestroyCine(Cine)
	If Cine=0
		Return False
	Else
		fx.Fx_Cine=Object.Fx_Cine(EntityName(Cine))
		If fx<>Null
			If fx\Sp<>0 FreeEntity Fx\Sp
			Delete fx
		EndIf
	EndIf
End Function




Function FX_Init_Fondu(camera,Mode%,Time%,FlipIt%=True,zoom#=1)
	fx.Fx_Fondu=New Fx_Fondu
	fx\Cam%		=	Camera
	fx\Zoom#	=	Zoom
	fx\Sp%		=	CreateSprite(Camera)
					MoveEntity	fx\Sp,0,0,fx\Zoom#*10	;	on decale le sprite assez loin et on le surdimensionns 
					ScaleSprite	fx\Sp,20,20				;	( en prevision d'un eventuel zoom )
					EntityColor	fx\Sp,0,0,0				;	 couleur du fondu
					EntityFX	fx\Sp,9+16				;	non affecté par le brouillard et les lumieres + double face
					EntityOrder	fx\Sp,-5000				;	affciéh devant tout ... enfin presque ...
					EntityAlpha	fx\Sp,0					;	Stade d'attente => alpha à 0
					HideEntity	fx\Sp					;	Stade d'attente, on le cache !

					NameEntity fx\Sp,Handle(fx)			;	Nomme le sprite par le handle du type
	; selection du mode
		fx\Mode%	=	Mode

		Select Mode
			Case 0	; fondu inactif
				fx\alpha#	=	0
				HideEntity fx\Sp
			Case -1
				ShowEntity fx\Sp
				fx\alpha#	=	1
			Case 1
				ShowEntity fx\Sp
				fx\alpha#	=	0
		End Select
	; ajuste l'alpha en fonction du mode
		EntityAlpha	fx\Sp,fx\alpha#
	; le fondu est il ancré dans une scene  ou se joue t'il dans une boucle independante ? ( arrêt de la scene )
		fx\FlipIt%	=	FlipIt
	Return fx\Sp
End Function



Function FX_MAJ_Fondu%(Camera,Fondu%,l_dt%=1,del%=False)
	fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
	If fx<>Null
		Select fx\FlipIT
			Case False
				Select fx\Mode
					Case 0	;	 mode attente => reste dans le dernier etat
					Case -1	; fondu In => on affiche l'ecran
						If fx\Time>0
							Fx\alpha	=	Fx\alpha-Float(l_Dt)/fx\Time
							ColR%		=	fx\S_ColR*(1-fx\Alpha)+fx\E_ColR*fx\Alpha
							ColG%		=	fx\S_ColG*(1-fx\Alpha)+fx\E_ColG*fx\Alpha
							ColB%		=	fx\S_ColB*(1-fx\Alpha)+fx\E_ColB*fx\Alpha
							If ColR<0		ColR=0
							If ColR>255		ColR=255
							If ColG<0		ColG=0
							If ColG>255		ColG=255
							If ColB<0		ColB=0
							If ColB>255		ColB=255
							EntityColor	Fx\Sp,ColR,ColG,ColB
							EntityAlpha	Fx\Sp,fx\Alpha
							If fx\alpha	<=	0
								fx\Mode	=	0	
								EntityAlpha fx\Sp,0:HideEntity fx\Sp
								EntityColor fx\Sp,fx\E_ColR,fx\E_ColG,fx\E_ColB
								; si pas de retour, le fondu est supprimé
								If del=True	FX_Destroy_Fondu(Fx\Sp)
							EndIf
							Return fx\Mode
						Else
							fx\Mode=0
							If del=True	FX_Destroy_Fondu(Fx\Sp)
						EndIf
					Case 1	; fondu Out => on cache l'ecran
						If fx\Time>0
							Fx\alpha	=	Fx\alpha+Float(l_Dt)/fx\Time
							ColR%		=	fx\S_ColR*(1-fx\Alpha)+fx\E_ColR*fx\Alpha
							ColG%		=	fx\S_ColG*(1-fx\Alpha)+fx\E_ColG*fx\Alpha
							ColB%		=	fx\S_ColB*(1-fx\Alpha)+fx\E_ColB*fx\Alpha
							If ColR<0		ColR=0
							If ColR>255		ColR=255
							If ColG<0		ColG=0
							If ColG>255		ColG=255
							If ColB<0		ColB=0
							If ColB>255		ColB=255
							EntityColor	Fx\Sp,ColR,ColG,ColB
							EntityAlpha	Fx\Sp,fx\Alpha
							If fx\alpha	>=	1
								fx\Mode	=	0	
								EntityAlpha fx\Sp,1
								EntityColor fx\Sp,fx\E_ColR,fx\E_ColG,fx\E_ColB
								; si pas de retour, le fondu est supprimé
								If del=True	FX_Destroy_Fondu(Fx\Sp)
							EndIf
							Return fx\Mode
						Else
							fx\Mode=0
							If del=True	FX_Destroy_Fondu(Fx\Sp)
						EndIf
				End Select
			Case True
				l_st%		=	MilliSecs()
				l_LT%		=	0
				Repeat
						l_mt%		=	MilliSecs()
						l_rDT%		=	l_mt-(l_st+l_LT)
						l_dt%		=	l_rdt
						If l_rdt<2		l_dt=2
						If l_rdt>60		l_dt=60
						l_LT		=	l_lt+l_dt
					Select fx\mode
						Case -1
							If fx\Time>0
								ShowEntity		fx\Sp
								Fx\alpha	=	Fx\alpha-Float(l_Dt)/fx\Time
								ColR%		=	fx\S_ColR*(1-fx\Alpha)+fx\E_ColR*fx\Alpha
								ColG%		=	fx\S_ColG*(1-fx\Alpha)+fx\E_ColG*fx\Alpha
								ColB%		=	fx\S_ColB*(1-fx\Alpha)+fx\E_ColB*fx\Alpha
								If ColR<0		ColR=0
								If ColR>255		ColR=255
								If ColG<0		ColG=0
								If ColG>255		ColG=255
								If ColB<0		ColB=0
								If ColB>255		ColB=255
								EntityColor	Fx\Sp,ColR,ColG,ColB
								EntityAlpha	Fx\Sp,fx\Alpha
								If fx\alpha	<=	0
									; si pas de retour, le fondu est supprimé
									If del=True	FX_Destroy_Fondu(Fx\Sp):Exit
									; sinon...
									fx_Mode	=	0
									EntityAlpha fx\Sp,0:HideEntity fx\Sp
									EntityColor fx\Sp,fx\E_ColR,fx\E_ColG,fx\E_ColB
									HideEntity	fx\Sp
									Exit
								EndIf
							Else
								fx\Mode=0
								If del=True	FX_Destroy_Fondu(Fx\Sp)
							EndIf
						Case 1
							If fx\Time>0
								ShowEntity		fx\Sp
								Fx\alpha	=	Fx\alpha+Float(l_Dt)/fx\Time
								ColR%		=	fx\S_ColR*(1-fx\Alpha)+fx\E_ColR*fx\Alpha
								ColG%		=	fx\S_ColG*(1-fx\Alpha)+fx\E_ColG*fx\Alpha
								ColB%		=	fx\S_ColB*(1-fx\Alpha)+fx\E_ColB*fx\Alpha
								If ColR<0		ColR=0
								If ColR>255		ColR=255
								If ColG<0		ColG=0
								If ColG>255		ColG=255
								If ColB<0		ColB=0
								If ColB>255		ColB=255
								EntityColor		Fx\Sp,ColR,ColG,ColB
								EntityAlpha		Fx\Sp,fx\Alpha
								If fx\alpha	>=	1
									; si pas de retour, le fondu est supprimé
									If del=True	FX_Destroy_Fondu(Fx\Sp):Exit
									; sinon...
									fx_Mode	=	0	
									EntityAlpha fx\Sp,1
									EntityColor fx\Sp,fx\E_ColR,fx\E_ColG,fx\E_ColB
									Exit
								EndIf
							Else
								fx\Mode=0
								If del=True	FX_Destroy_Fondu(Fx\Sp)
							EndIf
					End Select
					RenderWorld
					Flip
				Forever
				; si pas de retour, le fondu est supprimé
				If del=True FX_Destroy_Fondu(Fx_Sp) : Return False
		End Select
	EndIf
End Function


Function FX_Select_Fondu%(camera%)
	; si la camera existe !
	If camera<>0
		For fx.FX_Fondu=Each FX_Fondu
			; fondu existe , la camera coincide => on le retourne !
			If fx<> Null
				If fx\Cam=Camera
					Return fx\Sp
				EndIf
			EndIf
		Next
		; n'existe pas ? on en retourne un neuf, avec des param nuls
		fondu=FX_Init_Fondu(camera,0,0,0)
		Return fondu
	EndIf
	; sinon on retourne "0"
	Return False
End Function



Function FX_Get_Fondu_Time%(Fondu%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			Return fx\Time%
		EndIf
	EndIf
End Function



Function FX_Get_Fondu_Mode%(Fondu%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			Return fx\Mode%
		EndIf
	EndIf
End Function



Function FX_Get_Fondu_Flip%(Fondu%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			Return fx\FlipIt%
		EndIf
	EndIf
End Function



Function FX_Get_Fondu_Alpha#(Fondu%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			Return fx\Alpha#
		EndIf
	EndIf
End Function



Function FX_Get_Fondu_Camera%(Fondu%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			Return fx\Cam%
		EndIf
	EndIf
End Function




Function FX_Set_Fondu_Time%(Fondu%,Time%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			fx\Time%=Time
		EndIf
	EndIf
End Function


Function FX_Set_Fondu_EndColor(Fondu%,ColR%=0,ColG%=0,ColB%=0)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			fx\E_ColR%=ColR
			fx\E_ColG%=ColG
			fx\E_ColB%=ColB
		EndIf
	EndIf
End Function



Function FX_Set_Fondu_StartColor(Fondu%,ColR%=0,ColG%=0,ColB%=0)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			fx\S_ColR%=ColR
			fx\S_ColG%=ColG
			fx\S_ColB%=ColB
			If fx\Sp<>0 EntityColor fx\Sp,ColR,ColG,ColB
		EndIf
	EndIf
End Function



Function FX_Set_Fondu_Mode(Fondu%,Mode%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			fx\Mode=Mode
		EndIf
	EndIf
End Function



Function FX_Set_Fondu_Flip(Fondu%,FlipIt%)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			fx\FlipIt=FlipIt
		EndIf
	EndIf
End Function



Function FX_Set_Fondu_Camera%(Fondu%,Camera%)
	If Camera<>0
		If fondu<>0
			fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
			If fx<>Null
				If fx\Sp<>0
					EntityParent	fx\Sp,0
					PositionEntity	fx\Sp,EntityX(camera,1),EntityY(camera,1),EntityZ(camera,1)
					MoveEntity		fx\Sp,0,0,fx\zoom
					EntityParent	fx\Sp,Camera
					fx\cam		=	Camera
				EndIf
			EndIf
		EndIf
	EndIf
End Function



Function FX_Set_Fondu_alpha(Fondu%,Alpha#)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			fx\Alpha=Alpha
			If fx\Sp<>0 EntityAlpha fx\Sp,Alpha
		EndIf
	EndIf
End Function



Function FX_Set_Fondu_Zoom(Fondu%,Zoom#)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			If fx\Sp<>0
				MoveEntity fx\Sp,0,0,-fx\zoom*10
				fx\zoom=zoom
				MoveEntity fx\Sp,0,0,fx\zoom*10
			EndIf
		EndIf
	EndIf
End Function




Function FX_Destroy_Fondu(Fondu)
	If fondu<>0
		fx.FX_Fondu=Object.FX_Fondu(EntityName(Fondu))
		If fx<>Null
			If fx\Sp<>0
				EntityParent fx\Sp,0
				FreeEntity fx\Sp
			EndIf
			Delete fx
		EndIf
	EndIf
End Function