openb3dmax font size


👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈

 

Tweet
pino2

Why there is no function to change openb3dmax's font size?

pino2 commented:

I think because OpenB3D doesn't have text drawing command:
OpenB3D.pdf
Now, why not?
Multi-platform issues? most likely.

markcwm commented:

Hi pino, yes this was never added but it is not really an Openb3d but a Max2d question.

So the Text function in Openb3d uses GLDrawText which is a fixed point size of 8x16 and is only for debugging. If you want a custom size or font you use LoadImageFont, SetImageFont and then DrawText. I have a modified example of max2d.bmx to show a simple usage. One thing to be aware of is the url for LoadImageFont seems to not work if the path is relative, so the font must be in the same folder as the exe. Also I don't recommend modifying the Text function as it can cause draw conflicts with DrawText.

Here is the example. I hope that helps.

' max2d.bmx

SuperStrict

Framework Openb3d.B3dglgraphics
Import brl.freetypefont

?Not bmxng
Import Brl.Random
?bmxng
Import Brl.RandomDefault ' since v0.121
?
Import Brl.PngLoader

Global width%=DesktopWidth(),height%=DesktopHeight(),depth%=0,Mode%=2

Graphics3D width,height,depth,Mode

' Initialise MiniB3D program (spheremap)
' --------------------------------------

Local cam:TCamera=CreateCamera()
PositionEntity cam,0,0,-3

Local light:TLight=CreateLight()
RotateEntity light,90,0,0

' load object we will apply spheremap to - the classic teapot
Local teapot:TMesh=LoadMesh("../media/teapot.b3d")

' load texture with color + spherical environment map
Local tex:TTexture=LoadTexture("../media/spheremap.bmp",1+64)

' apply spherical environment map to teapot
EntityTexture teapot,tex

' Initialise Max2D program
' ------------------------

' Create a spark type
Type spark
    Field x#,y#,z#,vy#,xd#,yd#,zd#,r#,g#,b#,alpha#
End Type

' Load spark image
Global sparki:TImage=LoadImage("../media/spark.png")

' Set no. of sparks to be created per firework
Global no_sparks%=500

' Create spark list
Global spark_list:TList=New TList

' Load and set font
Global font:TImageFont=LoadImageFont("arial.ttf",24)
If Not font Then End
SetImageFont font

' Main loop
' ---------

' used by fps code
Local old_ms%=MilliSecs()
Local renders%, fps%

While Not KeyDown(KEY_ESCAPE)

    ' control camera
    MoveEntity cam,KeyDown(KEY_D)-KeyDown(KEY_A),0,KeyDown(KEY_W)-KeyDown(KEY_S)
    TurnEntity cam,KeyDown(KEY_DOWN)-KeyDown(KEY_UP),KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT),0

    TurnEntity teapot,0.5,0.75,1.0

    RenderWorld

    ' calculate fps
    renders=renders+1
    If Abs(MilliSecs() - old_ms) >= 1000
        old_ms=MilliSecs()
        fps=renders
        renders=0
    EndIf

    Text 0,20,"FPS: "+fps

    BeginMax2D() ' MiniB3D function
    UpdateMax2D() ' your function
    EndMax2D() ' MiniB3D function

    Flip
    Cls

Wend
End

Function UpdateMax2D()

    ' If space key pressed then create new set of sparks (new firework)

    If KeyHit(KEY_SPACE)

        Local x#=Rand(-100,100)
        Local y#=Rand(-100,100)
        Local z#=200

        Local r#=Rand(255)
        Local g#=Rand(255)
        Local b#=Rand(255)

        For Local i%=1 To no_sparks

            Local speed#=0.1

            Local ang1#=Rnd!(360)
            Local ang2#=Rnd!(360)

            Local sp:spark=New Spark
            spark_list.AddLast sp

            sp.x=x#
            sp.y=y#
            sp.z=z#

            sp.xd=Cos(ang1#)*Cos(ang2#)*speed#
            sp.yd=Cos(ang1#)*Sin(ang2#)*speed#
            sp.zd=Sin(ang1#)*speed#

            sp.r=r
            sp.g=g
            sp.b=b
            sp.alpha=1

        Next

    EndIf

    ' Draw all sparks

    For Local sp:spark=EachIn spark_list

        ' If spark alpha is above 0 then draw it...

        If sp.alpha>0

            sp.x=sp.x+sp.xd*10.0
            sp.y=sp.y+sp.yd*10.0
            sp.z=sp.z+sp.zd*10.0
            sp.y=sp.y+sp.vy#
            sp.vy=sp.vy+0.02

            ' Calculate x and y draw values based on x,y,z co-ordinates
            Local x#=(width/2.0)+((sp.x/sp.z)*500)
            Local y#=(height/2.0)+((sp.y/sp.z)*500)

            sp.alpha=sp.alpha-0.01

            SetColor sp.r#,sp.g#,sp.b#
            SetBlend LIGHTBLEND
            SetAlpha sp.alpha
            SetScale 20/sp.z,20/sp.z
            DrawImage sparki,x#,y#

        '...else remove spark from spark list

        Else

            spark_list.Remove sp

        EndIf

    Next

    SetBlend ALPHABLEND
    SetScale 1,1
    SetColor 255,127,0
    SetAlpha 1
    DrawText "Press space to ignite firework",240,320
    SetColor 0,127,255
    DrawText "Alpha blended text",320,480

End Function
pino2 commented:

So I have to use Max2D. Good, I like it. Thanks.
This works:

Framework Openb3d.B3dglgraphics
Import brl.freetypefont

Graphics3D 640,480,0,2

' font must be where executable file is
Global font:TImageFont=LoadImageFont("arial.ttf",24)
If Not font Then End
SetImageFont font

While Not KeyDown(KEY_ESCAPE)

    RenderWorld

    BeginMax2D() 
        DrawText "Hello", 20,20
    EndMax2D() 

    Flip
    Cls

Wend
End

Reply To Topic (minimum 10 characters)

Please log in to reply