Jump to content
IgorBgz90

Fonts [Solved]

Recommended Posts

Hi! I cannot understand how to use your font for button. And then use a standard font.

 

--Font
local context = Context:GetCurrent()
button.font = Font:Load("Fonts/Test.ttf",32) --Custom
button.defaultfont = context:GetFont() --Arial
button.color = Vec4(1.0)

 

Pay attention! I do not release fonts from memory.

 

 

function Button:Draw()
  local context = Context:GetCurrent()
  local window = Window:GetCurrent()
  if self.enable then
     if self.visible then
        context:SetBlendMode(Blend.Alpha)

        --Set user font
        if self.font then context:SetFont(self.font) else self.font = self.defaultfont end

        context:DrawText(self.title,25,25)

        --Set default font
        context:SetFont(self.defaultfont)

        context:SetBlendMode(Blend.Solid)
     end
  end
end

 

Log:

Executing "C:\Users\Igor\Documents\Leadwerks\Projects\MyGame\MyGame.exe"...

Initializing Lua...

Lua sandboxing enabled.

Executing file "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Scripts/Error.lua"

Executing file "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Scripts/App.lua"

Initializing OpenGL4 graphics driver...

OpenGL version 441

GLSL version 440

Device: AMD Radeon HD 6320 Graphics

Loading map "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Maps/start.map"...

Loading texture "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Materials/Common/bfn.tex"...

Loading texture "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/materials/sky/skybox_texture.tex"...

Loading font "C:/Windows/Fonts/Arial.ttf"...

Loading font "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Fonts/test.ttf"...

Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Editor/skybox.shader"...

Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Misc/occlusionquery.shader"...

Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Lighting/ambientlight.shader"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Drawing/drawtext.shader"...

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Loading font "C:/Windows/Fonts/Arial.ttf"...

Deleting font "C:/Windows/Fonts/Arial.ttf"

Process Complet

 

Maybe I'm doing something wrong?

Share this post


Link to post

Problem here:

button.defaultfont = context:GetFont()

 

It works:

button.defaultfont = Font:Load("Fonts/Arial.ttf",15)

Share this post


Link to post

Yes. you can either define a specific default font, or if you really want to know the used default font by the engine if you haven´t defined any you need to do

 

button.defaultfont = context:GetFont()
button.defaultfont:AddRef()

 

so the actual reference to it is added.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...