and add a new material to a specific plane entity as needed.
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
DeclareModule _Trilon
Enumeration
#FONT_DEFAULT
#ALIGN_TOPLEFT
#ALIGN_TOPCENTER
#ALIGN_TOPRIGHT
#ALIGN_MIDDELLEFT
#ALIGN_MIDDLECENTER
#ALIGN_MIDDLERIGHT
#ALIGN_BOTTOMLEFT
#ALIGN_BOTTOMCENTER
#ALIGN_BOTTOMRIGHT
EndEnumeration
Declare.i CreateTrilon()
Declare.i ChangeText(SideNum.i, Text.s, TextColor.i, Position.i = #ALIGN_MIDDLECENTER, BackGroundColor.i = $FFFFFF, Font.i = #FONT_DEFAULT)
Declare.i ChangeImage(SideNum.i, Image.i, Position.i = #ALIGN_MIDDLECENTER, BackGroundColor.i = $FFFFFF)
EndDeclareModule
Module _Trilon
#TexSize = 1024 ;Change for different texture size
Structure _object
ms.i
ma.i
tx.i
id.i
EndStructure
Structure _Sides
S1._object
S2._object
S3._object
nod.i ;for rotation...
EndStructure
Global Trilon._Sides
Procedure.i CreateTrilon()
Protected fn.i = LoadFont(#PB_Any, "Arial", 48)
Trilon\nod = CreateNode(#PB_Any, 0, 0, 0)
With Trilon\S1
\tx = CreateTexture(#PB_Any, #TexSize, #TexSize, "Base1")
StartDrawing(TextureOutput(\tx))
DrawingFont(FontID(fn))
DrawingMode(#PB_2DDrawing_Gradient)
BoxedGradient(0, 0, #TexSize, #TexSize)
GradientColor(0.64, $FF00FF)
Box(0, 0, #TexSize, #TexSize)
DrawText(0, 0, "PURPLE!!!!!", $FF0000)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
MaterialCullingMode(\ma, #PB_Material_NoCulling)
\ms = CreatePlane(#PB_Any, 60, 10, 1, 1, 1, 1)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -10/2.5, 0)
RotateEntity(\id, 180, 180, 0)
AttachNodeObject(Trilon\nod, EntityID(\id))
EndWith
With Trilon\S2
\tx = CreateTexture(#PB_Any, #TexSize, #TexSize, "Base2")
StartDrawing(TextureOutput(\tx))
DrawingFont(FontID(fn))
DrawingMode(#PB_2DDrawing_Gradient)
BoxedGradient(0, 0, #TexSize, #TexSize)
GradientColor(0.84, $00FFFF)
Box(0, 0, #TexSize, #TexSize)
DrawText(0, 0, "YELLOW!!!!!",$FF0000)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
MaterialCullingMode(\ma, #PB_Material_NoCulling)
\ms = CreatePlane(#PB_Any, 60, 10, 1, 1, 1, 1)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, -10/4)
RotateEntity(\id, 120, 0, 180, #PB_Absolute)
AttachNodeObject(Trilon\nod, EntityID(\id))
EndWith
With Trilon\S3
\tx = CreateTexture(#PB_Any, #TexSize, #TexSize, "Base3")
StartDrawing(TextureOutput(\tx))
DrawingFont(FontID(fn))
DrawingMode(#PB_2DDrawing_Gradient)
BoxedGradient(0, 0, #TexSize, #TexSize)
GradientColor(0.24, $000FFF)
Box(0, 0, #TexSize, #TexSize)
DrawText(0, 0, "REDDISH!!!",$FF0000)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
MaterialCullingMode(\ma, #PB_Material_NoCulling)
\ms = CreatePlane(#PB_Any, 60, 10, 1, 1, 1, 1)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 10/4)
RotateEntity(\id, 240, 0, 180, #PB_Absolute)
AttachNodeObject(Trilon\nod, EntityID(\id))
EndWith
ProcedureReturn Trilon\nod
EndProcedure
Procedure.i ChangeImage(SideNum.i, Image.i, Position.i = #ALIGN_MIDDLECENTER, BackGroundColor.i = $FFFFFF)
Protected tex.i, mat.i
If IsImage(Image) = 0 : ProcedureReturn #False : EndIf
tex = CreateTexture(#PB_Any, #TexSize, #TexSize)
StartDrawing(TextureOutput(tex))
Box(0, 0, #TexSize, #TexSize, BackGroundColor)
Select Position
Case #ALIGN_BOTTOMCENTER
DrawImage(ImageID(image), #TexSize/2 - ImageWidth(Image)/2, #TexSize - ImageHeight(image))
Case #ALIGN_BOTTOMLEFT
DrawImage(ImageID(Image), 0, #TexSize - ImageHeight(image))
Case #ALIGN_BOTTOMRIGHT
DrawImage(ImageID(Image), #TexSize - ImageWidth(image), #TexSize - ImageHeight(image))
Case #ALIGN_MIDDELLEFT
DrawImage(ImageID(Image), 0, #TexSize/2 - ImageHeight(Image)/2)
Case #ALIGN_MIDDLECENTER
DrawImage(ImageID(Image), #TexSize/2 - ImageWidth(image)/2, #TexSize/2 - ImageHeight(image)/2)
Case #ALIGN_MIDDLERIGHT
DrawImage(ImageID(Image), #TexSize - ImageWidth(image), #TexSize/2 - ImageHeight(image)/2)
Case #ALIGN_TOPCENTER
DrawImage(ImageID(Image), #TexSize/2 - ImageWidth(Image), 0)
Case #ALIGN_TOPLEFT
DrawImage(ImageID(Image), 0, 0)
Case #ALIGN_TOPRIGHT
DrawImage(ImageID(Image), #TexSize - ImageWidth(Image), 0)
EndSelect
StopDrawing()
mat = CreateMaterial(#PB_Any, TextureID(tex))
MaterialFilteringMode(mat, #PB_Material_Anisotropic, 8)
Select SideNum
Case 0
SetEntityMaterial(Trilon\S1\id, MaterialID(mat))
Case 1
SetEntityMaterial(Trilon\S2\id, MaterialID(mat))
Case 2
SetEntityMaterial(Trilon\S3\id, MaterialID(mat))
EndSelect
EndProcedure
Procedure.i ChangeText(SideNum.i, Text.s, TextColor.i, Position.i = #ALIGN_MIDDLECENTER, BackGroundColor.i = $FFFFFF, Font.i = #FONT_DEFAULT)
Protected tex.i, mat.i
tex = CreateTexture(#PB_Any, #TexSize, #TexSize)
StartDrawing(TextureOutput(tex))
DrawingMode(#PB_2DDrawing_Transparent)
If font <> #FONT_DEFAULT : DrawingFont(FontID(font)) : EndIf
Box(0, 0, #TexSize, #TexSize, BackGroundColor)
Select Position
Case #ALIGN_BOTTOMCENTER
DrawText((#TexSize/2) - (TextWidth(Text)/2), #TexSize - TextHeight(Text), Text, TextColor)
Case #ALIGN_BOTTOMLEFT
DrawText(4, #TexSize - TextHeight(Text), Text, TextColor)
Case #ALIGN_BOTTOMRIGHT
DrawText(#TexSize - TextWidth(Text), #TexSize - TextHeight(Text), Text, TextColor)
Case #ALIGN_MIDDELLEFT
DrawText(4, (#TexSize/2) - TextHeight(Text)/2, Text, TextColor)
Case #ALIGN_MIDDLECENTER
DrawText(#TexSize/2 - TextWidth(Text)/2, #TexSize/2 - TextHeight(Text)/2, Text, TextColor)
Case #ALIGN_MIDDLERIGHT
DrawText(#TexSize - TextWidth(Text), #TexSize/2 - TextHeight(Text)/2, Text, TextColor)
Case #ALIGN_TOPCENTER
DrawText(#TexSize/2 - TextWidth(Text)/2, TextHeight(Text), Text, TextColor)
Case #ALIGN_TOPLEFT
DrawText(0, 0, Text, TextColor)
Case #ALIGN_TOPRIGHT
DrawText(#TexSize, 0, Text, TextColor)
EndSelect
StopDrawing()
mat = CreateMaterial(#PB_Any, TextureID(tex))
MaterialFilteringMode(mat, #PB_Material_Anisotropic,8)
Select SideNum
Case 0
SetEntityMaterial(Trilon\S1\id, MaterialID(mat))
Case 1
SetEntityMaterial(Trilon\S2\id, MaterialID(mat))
Case 2
SetEntityMaterial(Trilon\S3\id, MaterialID(mat))
EndSelect
EndProcedure
EndModule
;EXAMPLE
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseGIFImageDecoder()
OpenWindow(0, 0, 0, 800, 600,"Trilon test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 80)
CreateLight(0, $FFFFFF, 0, 0, 80)
image.i = CreateImage(#PB_Any, 512, 512) ;test image
StartDrawing(ImageOutput(image))
For con.i = 0 To 256 Step 20
Box(con, con, 512-(con*2), 512-(con*2), RGB(Random(255,10), Random(255,10), Random(255,10)))
Next con
StopDrawing()
fn = LoadFont(#PB_Any, "Arial", 96, #PB_Font_Bold)
no.i = _Trilon::CreateTrilon()
el.i = ElapsedMilliseconds()
Repeat
Repeat: ev = WindowEvent() : Until ev = 0
RotateNode(no, 0.6, 0, 0, #PB_Relative)
If ElapsedMilliseconds() - el > 1500 ;Random side test
FontColor.i = RGB(Random(255, 10), Random(255, 10), Random(255, 10))
color.i = RGB(Random(255, 10), Random(255, 10), Random(255, 10))
If Random(500, 0) > 200
_Trilon::ChangeText(Random(2), "NEW TEXT", FontColor, Random(9,1), color, fn)
Else
_Trilon::ChangeImage(Random(2), image, Random(9,1), color)
EndIf
el = ElapsedMilliseconds()
EndIf
RenderWorld()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)