Cocoaでフルスクリーンモード

Cocoaアプリケーションでフルスクリーンを実現する方法です。
サンプルプログラムはESCキーを押すと終了します。

プログラム作成

MyOpenGLView.h

@interface MyOpenGLView:NSOpenGLView
{
	NSWindow *fullscreen_window;
}
@end

MyOpenGLView.m

- (void)awakeFromNib
{
	[[self window] makeFirstResponder:self];
	unsigned int window_style;
	NSRect screen_rect;
	window_style = NSBorderlessWindowMask;
	screen_rect = [[NSScreen mainScreen] frame];
	fullscreen_window = [[NSWindow alloc] initWithContentRect:screen_rect styleMask:window_style backing:NSBackingStoreBuffered defer:NO];
	if(fullscreen_window != nil)
	{
		[fullscreen_window setReleasedWhenClosed:YES];
		[fullscreen_window setContentView:self];
		[fullscreen_window makeKeyAndOrderFront:self];
		[fullscreen_window setLevel:NSScreenSaverWindowLevel - 1];
		[fullscreen_window makeFirstResponder:self];
	}
	[NSCursor hide];
}
NSOpenGLViewから派生したクラスのawakeFromNibに上記のコードを追加するだけ。
解像度はWindowsのDirectXと違い画面の解像度そのままでフルスクリーン化されるので注意が必要です。

各行の説明

サンプルプログラム

filefullscreen_source_20090615.zip

前に戻る?


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS