3D over SpriteCandy HUD

Blitz3D Forums/Blitz3D Userlibs/3D over SpriteCandy HUD

wmaass(Posted 2008) [#1]
Is it possible? For example I have am image of a landscape displayed on the screen using SpriteCandy, can I then have a 3D bird fly over it?


Mortiis(Posted 2009) [#2]
Do you have aShadow or FastExt? If so, you can do it via the RenderEntity command.


wmaass(Posted 2009) [#3]
I have both. Thanks for the tip, I'll give it a try. I have all of these great libraries and now I have the chance to put them to use!


Mortiis(Posted 2009) [#4]
Here is how I do it;

While bRunning = True

	UpdateGame()
	RenderWorld tween

	RenderPostprocess FE_DOF
	RenderPostprocess FE_Glow

	RenderEntity ( HUD_ReturnHUD( hud\hud ), Camera\cam )

	VWait : Flip False
Wend


In this code, I render the hud object again so it won't get effected by depth of field and glow. What you need to do is just rendering your 3D object after you updated your hud.


Uncle(Posted 2009) [#5]
Here's a demo I made a while showing how to do this with just SpriteCandy :

Graphics3D 800,600,0

Include "sprite candy.bb"

camera=CreateCamera()
light=CreateLight()
LightColor light,50,50,50

cube=CreateCube()
PositionEntity cube,0,0,5

Texture% = CreateTexture(256,256,1+256)
SetBuffer TextureBuffer(texture)
Color 0,0,250
Rect 0,0,256,256,1
Color 0,0,200
Rect 0,0,128,128,1
Rect 128,128,128,128,1
SetBuffer BackBuffer()
BackHUD% = HUD_Create (camera)
FrontHUD% = HUD_Create (camera)
Resource%    = HUD_LoadMemoryResource (Texture) 
BackImageLayer%  = HUD_CreateLayer        (BackHUD, Resource)
FrontImageLayer%  = HUD_CreateLayer        (FrontHUD%, Resource)
Texture          = HUD_GetTextureHandle   (Resource) 

; CREATED AN IMAGE THAT FITS ENTIRE SCREEN (BACK LAYER)
Image1%          = HUD_CreateImage (BackImageLayer, 0,0, 0,0,800,600, "CENTER","CENTER")
HUD_SetObjectScale Image1,2,2
HUD_SetObjectAlpha Image1,.5

; APPLY SOME EFFECTS
HUD_FX_SteadyScale Image1, 2,2,2*1.2,2*1.2,4000
HUD_FX_Ripple      Image1, 5,20,15

; NOW SOME OBJECTS INFRONT (FRONT LAYER)
ShapeHandle% =  HUD_CreateShape (  FrontImageLayer%,  "HOLLOWSTAR" ,  6,  60,  400,  300,  400,400 ) 

; APPLY SOME EFFECTS
EffectHandle% =  HUD_FX_Rotate (  ShapeHandle%,  360,  True, 7000, 0 ) 
EffectHandle% =  HUD_FX_SteadyScale (  ShapeHandle%,  0.5,  0.5,    1.5,  1.5, 3000,0) 
HUD_SetObjectColor (  ShapeHandle%,  0,  255,  255) 
HUD_SetObjectShadow (  ShapeHandle%,  True,  10  ) 

CameraClsMode camera,False,True

While Not KeyDown(1)
	If HUD_CountEffects(ShapeHandle,"ROTATE")=0 Then EffectHandle% =  HUD_FX_Rotate (  ShapeHandle%,  360,  True, 7000, 0 ) 
	If HUD_CountEffects(ShapeHandle,"COLORFADE")=0 Then 
		EffectHandle% =  HUD_FX_ColorFade (  ShapeHandle%,    255,255,0,    3000,0 ) 
		EffectHandle% = HUD_FX_ColorFade (  ShapeHandle%,    0,255,255,    3000,3000 ) 
		
	EndIf
	HUD_SetVisibility(BackHud,True)
	HideEntity cube
	HUD_Update()
	RenderWorld()
	HUD_SetVisibility(BackHud,False)
	ShowEntity cube
	TurnEntity cube,0.5,0.5,0.5
	RenderWorld 0
	Flip
Wend


The demo actually shows three layers. The first being a 2D SpriteCandy layer, then 3D Object Layer, and finally another 2D SpriteCandy layer on top.

Here is a simplier version with just 3D over 2D...

Graphics3D 800,600,0,2

Include "sprite candy.bb"

camera=CreateCamera()
light=CreateLight()
LightColor light,50,50,50

cube=CreateCube()
PositionEntity cube,0,0,5
EntityOrder cube,-100000 ; Important - Set the object order lower than any hud items so it is rendered over the top.

Texture% = CreateTexture(256,256,1+256)
SetBuffer TextureBuffer(texture)
Color 0,0,250
Rect 0,0,256,256,1
Color 0,0,200
Rect 0,0,128,128,1
Rect 128,128,128,128,1
SetBuffer BackBuffer()
BackHUD% = HUD_Create (camera)
FrontHUD% = HUD_Create (camera)
Resource%    = HUD_LoadMemoryResource (Texture) 
BackImageLayer%  = HUD_CreateLayer        (BackHUD, Resource)
FrontImageLayer%  = HUD_CreateLayer        (FrontHUD%, Resource)
Texture          = HUD_GetTextureHandle   (Resource) 

; CREATED AN IMAGE THAT FITS ENTIRE SCREEN (BACK LAYER)
Image1%          = HUD_CreateImage (BackImageLayer, 0,0, 0,0,800,600, "CENTER","CENTER")
HUD_SetObjectScale Image1,2,2
HUD_SetObjectAlpha Image1,.5

; APPLY SOME EFFECTS
HUD_FX_SteadyScale Image1, 2,2,2*1.2,2*1.2,4000
HUD_FX_Ripple      Image1, 5,20,15


CameraClsMode camera,False,True

While Not KeyDown(1)
	HUD_SetVisibility(BackHud,True)
	HUD_Update()
	RenderWorld()
	TurnEntity cube,0.5,0.5,0.5
	RenderWorld 0
	Flip
Wend


The important part in this code is to ensure you set your entityorders lower than any of the hud elements.

Cheers,


Unc


wmaass(Posted 2009) [#6]
Wow, that's really useful. Thanks for the help guys.