
If you can do better... do it and share!

Code: Select all
Global.b sal
Procedure spr2DText(spr, txt.s, font, ink.l=$ff00ff00)
Protected n,y=2,tl= CountString(txt,#CR$)
Protected tx.s
StartDrawing(SpriteOutput(spr))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,OutputWidth(),OutputHeight(),$00000000)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
Box(0,0,OutputWidth(),OutputHeight(),$aa000000)
DrawingFont(FontID(font))
For n=1 To tl+1
tx= StringField(txt,n,#CR$)
DrawText(5,y,tx,ink)
y+16
Next n
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Outlined)
Box(0,0,OutputWidth(),OutputHeight(),ink)
StopDrawing()
EndProcedure
Procedure iniDX(title.s="3D", width=800,height=600, shadowmode= #PB_Shadow_Modulative, shadowres=4096, param=#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0, 0, 0, width, height, title, param)
SetWindowColor(0,$444444)
OpenWindowedScreen(WindowID(0), 0, 0, (width * DesktopResolutionX()), (height * DesktopResolutionY()),0,0,0,#PB_Screen_NoSynchronization)
KeyboardMode(#PB_Keyboard_International)
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Model", #PB_3DArchive_FileSystem)
Add3DArchive("Data", #PB_3DArchive_FileSystem)
Parse3DScripts()
Protected.b s= 100
If shadowmode= #PB_Shadow_TextureAdditive Or shadowmode= #PB_Shadow_TextureModulative
WorldShadows(shadowmode, -1, RGB(s,s,s), shadowres)
Else
WorldShadows(shadowmode, -1, RGB(s,s,s))
EndIf
EndProcedure
Procedure eventosWindows()
Repeat
event= WindowEvent()
Select event
Case #PB_Event_Gadget
EventGadget= EventGadget()
EventType= EventType()
Case #PB_Event_CloseWindow
sal= 1
EndSelect
Until event= 0
EndProcedure
Procedure eventos3D(camara.i=0, speed.f=0.1, mousespeed.d=0.025)
Protected.f KeyX,KeyY
If ExamineKeyboard()
;{
If KeyboardReleased(#PB_Key_F1)
CameraRenderMode(camara, #PB_Camera_Wireframe)
EndIf
If KeyboardReleased(#PB_Key_F2)
CameraRenderMode(camara, #PB_Camera_Textured)
EndIf
If KeyboardReleased(#PB_Key_F3)
WorldDebug(#PB_World_DebugNone)
EndIf
If KeyboardReleased(#PB_Key_F4)
WorldDebug(#PB_World_DebugBody)
EndIf
If KeyboardReleased(#PB_Key_Pad9)
Debug "OK"
EndIf
If KeyboardPushed(#PB_Key_Escape)
sal=1
EndIf
If KeyboardPushed(#PB_Key_Left)
KeyX = -speed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = speed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -speed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = speed
Else
KeyY = 0
EndIf
;}
If KeyboardPushed(#PB_Key_A)
KeyX = -speed
ElseIf KeyboardPushed(#PB_Key_D)
KeyX = speed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_W)
KeyY = -speed
ElseIf KeyboardPushed(#PB_Key_S)
KeyY = speed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX() * mousespeed
MouseY = -MouseDeltaY() * mousespeed
mouseW = MouseWheel()
EndIf
RotateCamera(camara, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (camara, KeyX, 0, KeyY)
EndProcedure
Procedure creaLLuvia(size= 128, HQ.b=0)
Protected lluvia_imag, lluvia_mate, lluvia_bb, lluvia_nodo, lluvia_tx3d
Protected n,x,y,l
lluvia_imag= CreateImage(#PB_Any,size*2,size*2,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(lluvia_imag))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,OutputWidth(),OutputHeight(),$00ffffff)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
For y= 0 To OutputHeight() Step 15
For x= 0 To OutputWidth() Step 15
If Random(10)>8
l= Random(18,3)
LineXY(x,y,x+(l*0.5),y+l,$55ffffff)
; LineXY(x+1,y+1,x+1+(l*0.5),y+1+l,$88ffffff)
LineXY(-128+x,y,-128+x+(l*0.5),y+l,RGBA(255,255,255,n*15) )
EndIf
Next x
Next y
StopDrawing()
ResizeImage(lluvia_imag,size,size)
lluvia_tx3d= CreateTexture(#PB_Any,size,size,"rainTx3d")
StartDrawing(TextureOutput(lluvia_tx3d))
DrawAlphaImage(ImageID(lluvia_imag),0,0)
StopDrawing()
lluvia_mate= CreateMaterial(#PB_Any, TextureID(lluvia_tx3d))
MaterialShadingMode(lluvia_mate,#PB_Material_Flat)
DisableMaterialLighting(lluvia_mate, 1)
MaterialBlendingMode (lluvia_mate, #PB_Material_Add)
ScrollMaterial(lluvia_mate,0.2,0.8,#PB_Material_Animated)
ScaleMaterial(lluvia_mate,1/4,1/4)
SetMaterialAttribute(lluvia_mate,#PB_Material_DepthWrite,0)
lluvia_nodo= CreateNode(#PB_Any,0,0,0)
lluvia_bb= CreateBillboardGroup(#PB_Any, MaterialID(lluvia_mate),10,10)
AddBillboard(lluvia_bb,0,0,0)
AttachNodeObject(lluvia_nodo, BillboardGroupID(lluvia_bb))
If HQ
lluvia_mate2= CopyMaterial(lluvia_mate,#PB_Any)
ScrollMaterial(lluvia_mate2,0.1,0.6,#PB_Material_Animated)
lluvia_bb2= CreateBillboardGroup(#PB_Any, MaterialID(lluvia_mate2),10,10)
AddBillboard(lluvia_bb2,0,0,0)
AttachNodeObject(lluvia_nodo, BillboardGroupID(lluvia_bb2))
EndIf
; ResizeBillboard(0 , bb_lluvia, 10,10) ; NO FUNCIONA (error memory address???)
ScaleNode(lluvia_nodo,4,4,4,#PB_Absolute)
FreeImage(lluvia_imag)
ProcedureReturn lluvia_nodo
EndProcedure
Procedure posLLuvia(nodo, x.f,y.f,z.f, a.f,dist=10)
Protected.f nx,nz, na,aa
If a<0
na= Abs(a)
Else
na= (180-Abs(a))+180
EndIf
If na>=360:na-360:EndIf
aa= Radian(na-90)
nx= x + (Cos(aa) * dist)
nz= z + (Sin(aa) * dist)
MoveNode(nodo, nx, y, nz,#PB_Absolute)
EndProcedure
iniDX("Rain test v1 - [WASD+Mouse= Move]",1280,720)
;{ HUD
fnt1= LoadFont(#PB_Any,"Arial",9,#PB_Font_HighQuality)
spr1= CreateSprite(#PB_Any,100,100,#PB_Sprite_AlphaBlending)
;}
;{ SUELO
suelo_tx3D= CreateTexture(#PB_Any,128,128)
StartDrawing(TextureOutput(suelo_tx3D))
Box(0,0,OutputWidth(),OutputHeight(),$0)
Box(10,10,OutputWidth()-20,OutputHeight()-20,$ff0000)
StopDrawing()
size= 50
suelo_mesh= CreatePlane(#PB_Any,size,size,1,1,1,1)
suelo_mate= CreateMaterial(#PB_Any,TextureID(suelo_tx3D))
ScaleMaterial(suelo_mate,1/size,1/size)
suelo= CreateEntity(#PB_Any, MeshID(suelo_mesh), MaterialID(suelo_mate))
;}
;{ CÁMARA Y LUZ
luz= CreateLight(#PB_Any,$ffffff,0,50,0,#PB_Light_Directional)
LightDirection(luz,0.2,-0.4,0.3)
camara= CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(camara,0,10,15)
CameraRange(camara,0.1,1000)
CameraLookAt(camara,0,0,0)
;}
lluvia_nodo= creaLLuvia(256)
SetFrameRate(50) ;- active frame rate for smooth camera move / disable for speed test
Repeat
eventosWindows()
eventos3D(camara)
posLLuvia(lluvia_nodo, CameraX(camara),CameraY(camara),CameraZ(camara), CameraYaw(camara), 20)
ElapsedTime = RenderWorld()
;{ HUD
txt.s= "FPS: "+Str( Engine3DStatus(#PB_Engine3D_CurrentFPS) )+#CR$+#CR$+
"Rain test v1"+#CR$+
"minimy 2024"
If contador % 25 = 0
spr2DText(spr1,txt, fnt1, $ff00ffff )
EndIf
DisplayTransparentSprite(spr1, 10, 10)
;}
FlipBuffers()
contador+1
Delay(1)
Until sal=1