⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cirrdevicemacosx.mm

📁 game engine, which is useful for everyone who is interested in it. I hope you can enjoy it.
💻 MM
📖 第 1 页 / 共 2 页
字号:
// Copyright (C) 2005 Etienne Petitjean// This file is part of the "Irrlicht Engine".// For conditions of distribution and use, see copyright notice in Irrlicht.h#ifdef MACOSX#import <Cocoa/Cocoa.h>#import <OpenGL/gl.h>#include "CIrrDeviceMacOSX.h"#include "IEventReceiver.h"#include "irrList.h"#include "os.h"#include "CTimer.h"#include "irrString.h"#include "Keycodes.h"#include <stdio.h>#include <sys/utsname.h>#include "COSOperator.h"#include "irrlicht.h"#import <wchar.h>#import "AppDelegate.h"namespace irr{	namespace video	{		IVideoDriver* createOpenGLDriver(const core::dimension2d<s32>& screenSize, CIrrDeviceMacOSX *device, bool fullscreen, bool stencilBuffer, io::IFileSystem* io, bool vsync, bool antiAlias);	}} // end namespace irrstatic	bool	firstLaunch = true;namespace irr{//! constructorCIrrDeviceMacOSX::CIrrDeviceMacOSX(video::E_DRIVER_TYPE driverType, 				 const core::dimension2d<s32>& windowSize,				 u32 bits, bool fullscreen,				 bool sbuffer, bool vsync, 				 bool antiAlias, IEventReceiver* receiver,				 const char* version) : CIrrDeviceStub(version, receiver), DriverType(driverType), stencilbuffer(sbuffer){	struct	utsname	name;	NSString		*path;		#ifdef _DEBUG	setDebugName("CIrrDeviceMacOSX");	#endif	if (firstLaunch)	{		firstLaunch = false;		[[NSAutoreleasePool alloc] init];		[NSApplication sharedApplication];		[NSApp setDelegate:[[[AppDelegate alloc] initWithDevice:this] autorelease]];		[NSBundle loadNibNamed:@"MainMenu" owner:[NSApp delegate]];		[NSApp finishLaunching];		path = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];		chdir([path cString]);	}		_window = NULL;	_active = true;	_oglcontext = NULL;	_cglcontext = NULL;	uname(&name);	Operator = new COSOperator(name.version);	os::Printer::log(name.version,ELL_INFORMATION);	initKeycodes();	if (driverType != video::EDT_NULL) createWindow(windowSize,bits,fullscreen,vsync,stencilbuffer);	CursorControl = new CCursorControl(windowSize, this);	createDriver(driverType,windowSize,bits,fullscreen,stencilbuffer, antiAlias);	createGUIAndScene();}CIrrDeviceMacOSX::~CIrrDeviceMacOSX(){	closeDevice();}void	CIrrDeviceMacOSX::closeDevice(){	if (_window != NULL)	{		[_window setIsVisible:FALSE];		if (_oglcontext != NULL)		{			[_oglcontext clearDrawable];			[_oglcontext release];			_oglcontext = NULL;		}		[_window setReleasedWhenClosed:TRUE];		[_window release];		_window = NULL;	}	else	{		if (_cglcontext != NULL)		{			CGLSetCurrentContext(NULL);			CGLClearDrawable(_cglcontext);			CGLDestroyContext(_cglcontext);		}	}			_active = FALSE;	_cglcontext = NULL;}bool	CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& windowSize, irr::u32 bits, bool fullscreen, bool vsync, bool stencilBuffer){	int				index;	CGDisplayErr			error;	bool				result;	NSOpenGLPixelFormat		*format;	CGDirectDisplayID		display;	CGLPixelFormatObj		pixelFormat;	CGRect				displayRect;	CGLPixelFormatAttribute		fullattribs[32];	NSOpenGLPixelFormatAttribute	windowattribs[32];	CFDictionaryRef			displaymode,olddisplaymode;	long				numPixelFormats,newSwapInterval;		result = false;	display = CGMainDisplayID();	_screenWidth = (int) CGDisplayPixelsWide(display);	_screenHeight = (int) CGDisplayPixelsHigh(display);	if (!fullscreen)	{		_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,windowSize.Width,windowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];		if (_window != NULL)		{			index = 0;			windowattribs[index++] = NSOpenGLPFANoRecovery;				windowattribs[index++] = NSOpenGLPFADoubleBuffer;			windowattribs[index++] = NSOpenGLPFAAccelerated;			windowattribs[index++] = NSOpenGLPFADepthSize;			windowattribs[index++] = (NSOpenGLPixelFormatAttribute)16;			windowattribs[index++] = NSOpenGLPFAColorSize;			windowattribs[index++] = (NSOpenGLPixelFormatAttribute)bits;			if (stencilBuffer)			{				windowattribs[index++] = NSOpenGLPFAStencilSize;				windowattribs[index++] = (NSOpenGLPixelFormatAttribute)1;			}						windowattribs[index++] = (NSOpenGLPixelFormatAttribute)NULL;			format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];			if (format != NULL)			{				_oglcontext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];				[format release];			}						if (_oglcontext != NULL)			{				[_window center];				[_window setDelegate:[NSApp delegate]];				[_oglcontext setView:[_window contentView]];				[_window setAcceptsMouseMovedEvents:TRUE];				[_window setIsVisible:TRUE];				[_window makeKeyAndOrderFront:nil];				_cglcontext = (CGLContextObj) [_oglcontext CGLContextObj];				_width = windowSize.Width;				_height = windowSize.Height;				result = true;			}		}	}	else	{		displaymode = CGDisplayBestModeForParameters(display,bits,windowSize.Width,windowSize.Height,NULL);		if (displaymode != NULL)		{			olddisplaymode = CGDisplayCurrentMode(display);			error = CGCaptureAllDisplays();			if (error == CGDisplayNoErr)			{				error = CGDisplaySwitchToMode(display,displaymode);				if (error == CGDisplayNoErr)				{					pixelFormat = NULL;					numPixelFormats = 0;					index = 0;					fullattribs[index++] = kCGLPFAFullScreen;						fullattribs[index++] = kCGLPFADisplayMask;					fullattribs[index++] = (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display);					fullattribs[index++] = kCGLPFADoubleBuffer;					fullattribs[index++] = kCGLPFAAccelerated;					fullattribs[index++] = kCGLPFADepthSize;					fullattribs[index++] = (CGLPixelFormatAttribute)16;					fullattribs[index++] = kCGLPFAColorSize;					fullattribs[index++] = (CGLPixelFormatAttribute)bits;					if (stencilBuffer)					{						fullattribs[index++] = kCGLPFAStencilSize;						fullattribs[index++] = (CGLPixelFormatAttribute)1;					}										fullattribs[index++] = (CGLPixelFormatAttribute)NULL;					CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats); 					if (pixelFormat != NULL)					{						CGLCreateContext(pixelFormat,NULL,&_cglcontext);						CGLDestroyPixelFormat(pixelFormat);					}									if (_cglcontext != NULL)					{						CGLSetFullScreen(_cglcontext);						displayRect = CGDisplayBounds(display);						_width = (int)displayRect.size.width;						_height = (int)displayRect.size.height;						result = true;					}				}			}		}	}	if (result)	{		CGLSetCurrentContext(_cglcontext);		newSwapInterval = (vsync) ? 1 : 0;		CGLSetParameter(_cglcontext,kCGLCPSwapInterval,&newSwapInterval);		glViewport(0,0,_width,_height);		glMatrixMode(GL_PROJECTION);		glLoadIdentity();		glMatrixMode(GL_MODELVIEW);		glLoadIdentity();	}	return (result);}void	CIrrDeviceMacOSX::setResize(int width,int height){	_width = width;	_height = height;	[_oglcontext update];	getVideoDriver()->OnResize(core::dimension2d<s32>(width, height));}void	CIrrDeviceMacOSX::createDriver(video::E_DRIVER_TYPE driverType,const core::dimension2d<s32>& windowSize,u32 bits,bool fullscreen,bool stencilbuffer, bool antiAlias){	switch (driverType)	{		case video::EDT_SOFTWARE:			VideoDriver = video::createSoftwareDriver(windowSize, fullscreen, FileSystem, this);			break;				case video::EDT_SOFTWARE2:			VideoDriver = video::createSoftwareDriver2(windowSize, fullscreen, FileSystem, this);			break;		case video::EDT_OPENGL:		#ifdef _IRR_COMPILE_WITH_OPENGL_			VideoDriver = video::createOpenGLDriver(windowSize, this, fullscreen, stencilbuffer, FileSystem, false, antiAlias);		#endif			break;		case video::EDT_NULL:			VideoDriver = video::createNullDriver(FileSystem, windowSize);			break;		default:			os::Printer::log("This driver is not available in Linux. Trying OpenGL.", ELL_WARNING);	}}void	CIrrDeviceMacOSX::flush(){	if (_cglcontext != NULL)	{		glFinish();		CGLFlushDrawable(_cglcontext);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -