Trick : Drawing text on the 3D scene

Everything related to 3D programming
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Trick : Drawing text on the 3D scene

Post by Comtois »

while waiting for a DrawText3D() solution, we can use Sprite ou Billboard

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

Declare DrawText3D(x.f, y.f, z.f, Texte$, FrontColor, BackColor)
  
OpenWindow(0,0,0,800,600,"3D",#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)
LoadFont(0, "Arial", 12, #PB_Font_Bold)

CreateTexture(0, 64, 64)
CreateMaterial(0, TextureID(0))
MaterialBlendingMode(0, #PB_Material_Add)
MaterialSelfIlluminationColor(0, $FFFFFF)

; Then create the billboard group and use the previous material
;
CreateBillboardGroup(0, MaterialID(0), 64, 64)
AddBillboard(0, 0, 32, -32, 0)

CreateCube(0, 100)
CreateEntity(0, MeshID(0), #PB_Material_None)

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 0, 100, 600)
CameraLookAt(0, EntityX(0), EntityY(0) + 10, EntityZ(0))

CreateSprite(0, 64, 64)

Repeat
  
  If ExamineMouse()
  EndIf
  
  If ExamineKeyboard()
  EndIf
  Texte$ = StrF(Engine3DFrameRate(#PB_Engine3D_Current),2)
  DrawText3D(EntityX(0) -32, EntityY(0)+ 80, EntityZ(0), Texte$, RGB(255,255,0), 0) 
  RenderWorld()
  StartDrawing(SpriteOutput(0))
  DrawingFont(FontID(0))
  DrawText(0, 0, Texte$, RGB(255,255,0))
  StopDrawing()
  x = CameraProjectionX(0,EntityX(0) + 60, EntityY(0)+ 80, EntityZ(0))
  y = CameraProjectionY(0,EntityX(0) + 60, EntityY(0)+ 80, EntityZ(0))
  DisplayTransparentSprite(0, x, y)
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

Procedure DrawText3D(x.f, y.f, z.f, Texte$, FrontColor, BackColor)
  StartDrawing(TextureOutput(0))
  Box(0, 0, OutputWidth(), OutputHeight(), BackColor)
  DrawingFont(FontID(0))
  DrawText(0, 0, Texte$, FrontColor)
  StopDrawing()
  
  BillboardGroupLocate(0, x, y, z)

EndProcedure
Please correct my english
http://purebasic.developpez.com/
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Trick : Drawing text on the 3D scene

Post by Danilo »

Your DrawText3D() shows the first character of the string only, when compiled with Unicode in PB4.61.

In ASCII mode it outputs "59.94", in Unicode mode "5". DrawText() on TextureOutput() takes only ASCII text? (maybe small bug?)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Trick : Drawing text on the 3D scene

Post by Comtois »

with Unicode in PB4.61.
Try 5.00 beta 5 :)


Another great way for drawing text3D here
Please correct my english
http://purebasic.developpez.com/
Post Reply