Code: Select all
;Billboard Text
;PB 5.00 beta 5
;by einander
EnableExplicit
#Box=3
#Ellip=4
#Text=5 ; Text with transparent background
#BkRGB=$22
Define Ev
Global _MainNode,_CamSpeed.D=1, _Separation=40
;
Define MyFont12=FontID(LoadFont(-1,"courier new",12,#PB_Font_HighQuality))
Define MyFont16=FontID(LoadFont(-1,"comic sans ms",16,#PB_Font_HighQuality))
;
Procedure CenterText(X,Y,X1,Y1,Tx.S,FontID,TextRGB=0,BkRGB=$FFFFFF)
Protected TextWidth=TextWidth(Tx),TextHeight=TextHeight(Tx)
DrawingMode(#PB_2DDrawing_Transparent)
If TextWidth>X1-X
DrawText(X,(Y1+Y)/2-TextHeight/2 , Tx, TextRGB)
Else
DrawText((X1+X)/2-TextWidth/2, (Y1+Y)/2-TextHeight/2 , Tx, TextRGB)
EndIf
EndProcedure
;
Procedure KeyMap(Camera=0,MainNode=0) ; Control moving and rotating with Keyboard
;keys Left,Right,Up,Down,PageUp,PageDown,Insert,Delete,Home,End ,+,-, F1 to F8
; -------
Macro KBP(Key1,Key2)
(KeyboardPushed(#PB_Key_#Key1) Or KeyboardPushed(#Pb_Key_#Key2))
EndMacro
; -------
If KBP(ADD,F1)
MoveCamera(Camera, 0,0, -_CamSpeed*2) ; move to front
ElseIf KBP(Subtract,F2)
MoveCamera(Camera, 0, 0,_CamSpeed*2) ; move to rear
; ------------------------------
; Arrow keys; move camera to 4 absolute Directions
ElseIf KeyboardPushed(#PB_Key_Left)
MoveCamera(Camera, _CamSpeed, 0, 0) ; Move to screen Left
ElseIf KeyboardPushed(#PB_Key_Right)
MoveCamera(Camera, -_CamSpeed, 0, 0) ; Move to screen Right
ElseIf KeyboardPushed(#PB_Key_Up)
MoveCamera(Camera, 0,-_CamSpeed, 0) ; Move to screen Top
ElseIf KeyboardPushed(#PB_Key_Down)
MoveCamera(Camera, 0,_CamSpeed, 0) ; Move to screen Bottom
; -------------------
;PageUp - Insert : Home - End : Delete - PageDown ; 6 rotations relative to object position
ElseIf KBP(F3,PageUp)
RotateNode(MainNode,0,0,_CamSpeed*2,#PB_Relative) ; Turn Left
ElseIf KBP(F4,Insert)
RotateNode(MainNode,0,0,-_CamSpeed*2,#PB_Relative) ; Turn Right
; ---------------------
;Home / End
ElseIf KBP(F5,Home)
RotateNode(MainNode,-_CamSpeed,0,0,#PB_Relative) ; Turn back
ElseIf KBP(F6,End)
RotateNode(MainNode,_CamSpeed,0,0,#PB_Relative) ; Turn front
; -------------
;Delete / PageDown
ElseIf KBP(F7,Delete)
RotateNode(MainNode,0, _CamSpeed,0,#PB_Relative) ; Rotation Left
ElseIf KBP(F8,PageDown)
RotateNode(MainNode,0, -_CamSpeed,0,#PB_Relative) ; Rotation Right
EndIf
NodeLookAt(MainNode,0,0,0)
EndProcedure
;
Procedure Link(Node1,Node2,RGB1=$FFFFFF,RGB2=$FFFFFF)
Static NR
CreateLine3D(Nr,NodeX(Node1),NodeY(Node1),NodeZ(Node1),RGB1,NodeX(Node2),NodeY(Node2),NodeZ(Node2),RGB2)
Nr+1
EndProcedure
;
Procedure BBText(Index,Wi,He,Shape,T$,X,Y,Z,FontID,TextRGB,BkRGB,GradRGB=-1)
CreateTexture(Index,Wi,He)
StartDrawing(TextureOutput(Index))
Box(0,0,Wi,He,0)
DrawingFont(FontID)
If GradRGB=-1:GradRGB=BkRGB:EndIf
Protected Po=1,A$,Yy=2
Select Shape
Case #Text
CenterText(0,2,Wi,He,T$,FontID,TextRGB)
Case #Ellip
DrawingMode(#PB_2DDrawing_Gradient)
BackColor(BkRGB)
GradientColor(0.5, GradRGB)
EllipticalGradient(Wi/2,He/2,Wi,He)
Ellipse(Wi/2,He/2,WI/2,HE/2)
CenterText(0,0,WI,HE,T$,#TRANSPARENT,TextRGB)
Case #Box
DrawingMode(#PB_2DDrawing_Gradient)
BackColor(BkRGB)
GradientColor(0.8, GradRGB)
LinearGradient(0, 0, Wi,He)
Box(0,0,Wi,He)
DrawingMode(#PB_2DDrawing_Transparent)
If FindString(T$,"|")
PO=01
Repeat
A$=StringField(T$,Po,"|") ;separator for multiLines
If A$="":Break:EndIf
DrawText(0,Yy,A$,TextRGB)
Po+1
Yy+TextHeight("T")
ForEver
EndIf
EndSelect
StopDrawing()
CreateMaterial(Index,TextureID(Index) )
MaterialBlendingMode(Index, #PB_Material_Color) ; make transparent background; comment to test
CreateBillboardGroup(Index, MaterialID(Index), Wi,He)
AddBillboard(Index, Index,0,0,0)
CreateNode(Index,X*_Separation,Y*_Separation,Z*_Separation)
AttachNodeObject(Index,BillboardGroupID(Index))
EndProcedure
;
InitEngine3D()
InitKeyboard()
InitSprite()
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Define T$="Keys Left,Right,Up,Down,PageUp,PageDown,Insert,Delete,Home,End ,+,-, F1 to F8"
OpenWindow(0, 0, 0, 800,600,T$,#PB_Window_Maximize)
SetWindowColor(0,0)
Define Wi=WindowWidth(0)
Define He=WindowHeight(0)
AntialiasingMode(#PB_AntialiasingMode_x4)
; ----------------------------
OpenWindowedScreen(WindowID(0), 0, 30, Wi-130,He-30, 0, 0, 0,#PB_Screen_SmartSynchronization)
_MainNode=CreateNode(-1,0,0,0)
;
BBText(1,180,30,#Text,"Transparent Text 1",-1, -1, 3,Myfont16, $FF,0,0)
BBText(2,180,40,#Ellip,"Ellipse 2",1, 3, 0,Myfont16, #Green,$FABADA,$FFFFFF)
BBText(3,180,66,#Box," Rectangle 3| MultiLine| yellow & green",-3, 0, 0,Myfont12, $FF0000,$FFFF,$FFFF00)
Link(1,2,$FF)
Link(2,3,$FF)
Link(3,1,$FF)
;
CreateLight(0, #White, 0, 1200, 0, #PB_Light_Spot)
SpotLightRange(0, 1, 10, 3)
AmbientColor($BBFF)
;
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 0, 0, 600)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, #BkRGB)
AttachNodeObject(_MainNode,CameraID(0))
Define Draw=1
Repeat
Repeat
Ev=WindowEvent()
If Ev=#PB_Event_CloseWindow:Break 2:EndIf
Until Ev=0
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape) : Break : EndIf
Keymap(0,_MainNode)
Draw=1
EndIf
If Draw
RenderWorld()
FlipBuffers()
Draw=0
EndIf
ForEver
End