Jump to content

Fonts [Solved]


IgorBgz90
 Share

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?

Link to comment
Share on other sites

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.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...