From ec23d7ed551de4d1399bb9cd869e368698ee5d81 Mon Sep 17 00:00:00 2001 From: yangws Date: Mon, 23 May 2011 16:21:31 +0800 Subject: [PATCH] fixed #508 Dynamic switch retina display support. --- cocos2dx/CCDirector.cpp | 10 ++++++++-- cocos2dx/platform/ios/CCEGLView_ios.mm | 4 +++- tests/test.ios/Classes/testsAppDelegate.mm | 23 +++++++++++----------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 9e6ebd9076..f1532716ea 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -306,7 +306,10 @@ void CCDirector::setProjection(ccDirectorProjection kProjection) { case kCCDirectorProjection2D: // glViewport((GLsizei)0, (GLsizei)0, (GLsizei)size.width, (GLsizei)size.height); - CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height); + if (m_pobOpenGLView) + { + m_pobOpenGLView->setViewPortInPoints(0, 0, size.width, size.height); + } glMatrixMode(GL_PROJECTION); glLoadIdentity(); ccglOrtho(0, size.width, 0, size.height, -1024 * CC_CONTENT_SCALE_FACTOR(), @@ -317,7 +320,10 @@ void CCDirector::setProjection(ccDirectorProjection kProjection) case kCCDirectorProjection3D: // glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height); - CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height); + if (m_pobOpenGLView) + { + m_pobOpenGLView->setViewPortInPoints(0, 0, size.width, size.height); + } glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f); diff --git a/cocos2dx/platform/ios/CCEGLView_ios.mm b/cocos2dx/platform/ios/CCEGLView_ios.mm index e6b62f4b12..bee08fc2cb 100644 --- a/cocos2dx/platform/ios/CCEGLView_ios.mm +++ b/cocos2dx/platform/ios/CCEGLView_ios.mm @@ -60,7 +60,9 @@ bool CCEGLView::isOpenGLReady() void CCEGLView::setContentScaleFactor(float contentScaleFactor) { - [[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor]; + UIView * view = [EAGLView sharedEGLView]; + view.contentScaleFactor = contentScaleFactor; + [view setNeedsLayout]; } void CCEGLView::release() diff --git a/tests/test.ios/Classes/testsAppDelegate.mm b/tests/test.ios/Classes/testsAppDelegate.mm index ff632c1c90..c0ad31a32d 100644 --- a/tests/test.ios/Classes/testsAppDelegate.mm +++ b/tests/test.ios/Classes/testsAppDelegate.mm @@ -28,24 +28,23 @@ static AppDelegate s_sharedApplication; // Add the view controller's view to the window and display. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; - // Init the View Controller - viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - viewController.wantsFullScreenLayout = YES; - + // Init the EAGLView EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 depthFormat: GL_DEPTH_COMPONENT16_OES preserveBackbuffer: NO - sharegroup:nil - multiSampling:NO - numberOfSamples:0]; + sharegroup: nil + multiSampling: NO + numberOfSamples: 0]; [__glView setMultipleTouchEnabled:YES]; - // make the OpenGLView a child of the view controller - [viewController setView:__glView]; - - // make the View Controller a child of the main window - [window addSubview: viewController.view]; + // Use RootViewController manage EAGLView + viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; + viewController.wantsFullScreenLayout = YES; + viewController.view = __glView; + + // Set RootViewController to window + window.rootViewController = viewController; [window makeKeyAndVisible]; [[UIApplication sharedApplication] setStatusBarHidden:true];