doterax's picture

How to fix double change of screen resolution in Mac OS X

Project:The Open Toolkit library
Version:1.0.0-rc1
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:open
Description

In source file OpenTK/Platform/MacOS/AglContext.cs you can find this comment and code:

// This is a weird hack to workaround a bug where the first time a context
// is made fullscreen, we just end up with a blank screen.  So we undo it as fullscreen
// and redo it as fullscreen.  
if (firstFullScreen == false)
{
       firstFullScreen = true;
       UnsetFullScreen(info);
       SetFullScreen(info, ref width, ref height);
}

But you can fix this fix :-) if you call Agl.aglSetDrawable(aglContextHandle, IntPtr.Zero) BEFORE call Agl.aglSetFullScreen

My code of SetFullScreen

internal void SetFullScreen(CarbonWindowInfo info, int width, int height)
{
	IntPtr display = GetQuartzDevice(info);
 
	IntPtr requestedMode = GetBestDisplayMode(display, width, height, 32);
 
 
	if(requestedMode == IntPtr.Zero)
	{
		Agl.aglSetFullScreen(aglContextHandle, width, height, 60, 0);
	}
	else
	{
		if (_lastMode == IntPtr.Zero)
			_lastMode = CG.DisplayCurrentMode(display);
		CG.DisplaySwitchToMode(display, requestedMode);
 
		Agl.aglSetDrawable(aglContextHandle, IntPtr.Zero);
 
		Agl.aglEnable(aglContextHandle, Agl.ParameterNames.AGL_FS_CAPTURE_SINGLE);
		Agl.aglSetFullScreen(aglContextHandle, 0, 0, 0, 0);
 
		Agl.aglSetCurrentContext(aglContextHandle);
		Agl.aglUpdateContext(aglContextHandle);
	}
	mIsFullscreen = true;
}

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kvark's picture

#1

Nice catch!