Jump to content

How to change font size


Slastraf
 Share

Recommended Posts

--Create the graphics context

context=Context:Create(window,0)

local font = Font:Load("Fonts/SOTRD.ttf",36)

context:SetFont(font)

context:SetScale(1,1)

if context==nil then return end

 

I have this in my main.lua but how do I now change the font size ?

when I change the Context Scale it changes the window , too but I only want to change the font size

Link to comment
Share on other sites

Basically either load another/same font at a different size and set the context's font with it or you can set the scale of the context to change the size of an existing loaded font. Note that scaling up a font alot usually cause loss of definition on the text shape.

 

window = Window:Create()

context = Context:Create(window)

local font = Font:Load("Fonts/Arial.ttf",36)

local font2 = Font:Load("Fonts/Arial.ttf",72)

context:SetFont(font)

local x = 50

local y = 50

while window:KeyDown(Key.Escape)==false do

context:SetColor(0,0,0)

context:Clear()

 

context:SetBlendMode(Blend.Alpha)

context:SetColor(1,1,1)

context:DrawText("Arial 36 1x1 scale",x,y)

context:SetScale(2,2)

context:SetColor(1,0,0,1)

context:DrawText("Arial 36 2x2 scale",x+50,y+50)

context:SetScale(1,1)

context:SetColor(0,1,0,1)

context:SetFont(font2)

context:DrawText("Arial 72 1x1 scale" ,x+150,y+150)

context:SetFont(font)

context:SetBlendMode(Blend.Solid)

 

context:Sync()

end

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

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...