Jump to content

Script to start full screen by holding a key


Einlander
 Share

Recommended Posts

When I use Leadwerks I normally have my game run at desktop resolution windowed. Sometimes I want to see the performance difference in full screen (it's always better). To do this I would normally need to edit main.lua. After a bit of thinking and experimenting I made a short 'hack' that will allow you to hold f5 of f6 to run in full screen instead of windowed.

 


tempwindow=Window:Create("key capture",0,0,1,1,1)

context=Context:Create(tempwindow,0)

if (tempwindow:KeyDown(Key.F5) or tempwindow:KeyDown(Key.F6))== true then

windowstyle=windowstyle+window.FullScreen

end

 

Place this after

if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end

and before

 

window=Window:Create(title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)

Link to comment
Share on other sites

you can switch window styles in-game (at least this small example seems to work - haven't tried it on anything of significance):

count = System:CountGraphicsModes()

rescounter = 0

resolutions = {}

for i = 0, count-1 do resolutions = System:GetGraphicsMode(i) end

window = Window:Create("window properties", 0,0,resolutions[0].x,resolutions[0].y,1+16)

context = Context:Create(window)

world = World:Create()

camera = Camera:Create()

camera:Move(0,0,-3)

light = DirectionalLight:Create()

light:SetRotation(35,35,0)

model = Model:Box()

model:SetColor(1.0,0.5,0.0)

style = "Titlebar+Center"

 

function ResMinMax(v)

v = math.min(v, count-1)

v = math.max(v, 0)

window:SetLayout(0,0,resolutions[v].x,resolutions[v].y)

return v

end

 

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

if window:Closed() then break end

 

if window:KeyHit(Key.Down) then rescounter = ResMinMax(rescounter - 1) end

if window:KeyHit(Key.Up) then rescounter = ResMinMax(rescounter + 1) end

 

if window:KeyHit(Key.Space) then

context:Release()

window:Release()

if style == "Borderless+Center" then

window = Window:Create("titlebar", 0, 0, resolutions[rescounter].x,resolutions[rescounter].y,1)

style = "Titlebar"

elseif style == "Titlebar" then

window = Window:Create("titlebar+center", 0, 0, resolutions[rescounter].x,resolutions[rescounter].y,1+16)

style = "Titlebar+Center"

elseif style == "Titlebar+Center" then

window = Window:Create("fullscreen", 0, 0, resolutions[rescounter].x,resolutions[rescounter].y,0)

style = "Borderless"

else

window = Window:Create("fullscreen", 0, 0, resolutions[rescounter].x,resolutions[rescounter].y,16)

style = "Borderless+Center"

end

context = Context:Create(window)

end

 

model:Turn(0,Time:GetSpeed(),0)

Time:Update()

world:Update()

world:Render()

context:SetBlendMode(Blend.Alpha)

context:DrawText("Number of Resolutions: "..count,2,22)

context:DrawText("Resolution: "..rescounter.."-- "..resolutions[rescounter].x.."x"..resolutions[rescounter].y,2,42)

context:DrawText("Window Style: "..style,2,92)

context:DrawText("Hit UP/DOWN to change resolution",2,2)

context:DrawText("Hit SPACE to change style ",2,72)

context:SetBlendMode(Blend.Solid)

context:Sync(true)

end

  • Upvote 2

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

Yeah but iirc you can't actually go fullscreen after you start with any windowed/windowed borderless mode.

 

Sure you can. Its just a combination of setting the proper style then performing a set layout if needed. The script above can do that.

 

Edit--Now granted this may be something fairly new within the last several months as before I think it would crash doing that, but I have been doing this since at least September.

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