Jump to content
Haydenmango

Toggle Fullscreen using Window:SetLayout()

Recommended Posts

I may be wrong but it seems that you can't change the fullscreen setting after you create the window for your game.

Would it be possible to add the ability to toggle fullscreen mode through the Window:SetLayout() function?

Share this post


Link to post

I am able to toggle fullscreen mode using SetLayout when I set the window style to '0' upon creation.

 

It would be nice to be able to set the window styles between the two states though.

 

What I haven't figured out what to do yet though is to change resolutions but be at fullscreen along with keeping the ability to go to a windowed mode. I think the missing ability to set the window style is the problem.

 

count = System:CountGraphicsModes()

resolutions = {}

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

window = Window:Create("window properties", 0,0,800,600,0)

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)

 

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

if window:Closed() then break end

 

if window:KeyHit(Key.Down) then window:SetLayout(0,0,800,600) end

if window:KeyHit(Key.Up) then window:SetLayout(0,0,resolutions[count-1].x,resolutions[count-1].y) end

 

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

Time:Update()

world:Update()

world:Render()

context:SetBlendMode(Blend.Alpha)

context:DrawStats(0,0,true)

context:Sync(true)

end

Share this post


Link to post

I just managed to make it work by releasing the window & context and re-creating them. I haven't tested it thoroughly, just wrote the code and it worked. smile.png

 

Obviously you should replace the windows code for getting the desktop resolution with something else.

 

In your loop:

if (window->KeyHit(Key::F)) {
	window->Release();
	context->Release();
	if (fullscreen == false) {
		RECT desktop;
		const HWND hDesktop = GetDesktopWindow();
		GetWindowRect(hDesktop, &desktop);

		window = Leadwerks::Window::Create("Lands of nowhere", 0, 0, desktop.right, desktop.bottom, Window::FullScreen);
	}
	else {
		window = Leadwerks::Window::Create("Lands of nowhere", 70, 70, 1024, 768);
	}
	context = Context::Create(window);
	fullscreen = !fullscreen;
	return true;
}

Share this post


Link to post

Works but that method in lua will cause the program to shut down half the time. Also, your method in lua appears to make the memory usage go up 3-4GBs each time. The SetLayout method doesn't do that - at least in lua (or at least in much smaller amounts).

Share this post


Link to post

Works but that method in lua will cause the program to shut down half the time. Also, your method in lua appears to make the memory consumption go up each time. The SetLayout method doesn't do that - at least in lua.

Yeah i was afraid that might happen in lua or even in linux, i guess it's unsafe to use. sad.png

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