fixed #508 Dynamic switch retina display support.

This commit is contained in:
yangws 2011-05-23 16:21:31 +08:00
parent 533949a736
commit ec23d7ed55
3 changed files with 22 additions and 15 deletions

View File

@ -306,7 +306,10 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
{ {
case kCCDirectorProjection2D: case kCCDirectorProjection2D:
// glViewport((GLsizei)0, (GLsizei)0, (GLsizei)size.width, (GLsizei)size.height); // 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); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
ccglOrtho(0, size.width, 0, size.height, -1024 * CC_CONTENT_SCALE_FACTOR(), ccglOrtho(0, size.width, 0, size.height, -1024 * CC_CONTENT_SCALE_FACTOR(),
@ -317,7 +320,10 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
case kCCDirectorProjection3D: case kCCDirectorProjection3D:
// glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height); // 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); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f); gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f);

View File

@ -60,7 +60,9 @@ bool CCEGLView::isOpenGLReady()
void CCEGLView::setContentScaleFactor(float contentScaleFactor) void CCEGLView::setContentScaleFactor(float contentScaleFactor)
{ {
[[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor]; UIView * view = [EAGLView sharedEGLView];
view.contentScaleFactor = contentScaleFactor;
[view setNeedsLayout];
} }
void CCEGLView::release() void CCEGLView::release()

View File

@ -28,24 +28,23 @@ static AppDelegate s_sharedApplication;
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
// Init the View Controller // Init the EAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16_OES depthFormat: GL_DEPTH_COMPONENT16_OES
preserveBackbuffer: NO preserveBackbuffer: NO
sharegroup:nil sharegroup: nil
multiSampling:NO multiSampling: NO
numberOfSamples:0]; numberOfSamples: 0];
[__glView setMultipleTouchEnabled:YES]; [__glView setMultipleTouchEnabled:YES];
// make the OpenGLView a child of the view controller // Use RootViewController manage EAGLView
[viewController setView:__glView]; viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
viewController.view = __glView;
// make the View Controller a child of the main window // Set RootViewController to window
[window addSubview: viewController.view]; window.rootViewController = viewController;
[window makeKeyAndVisible]; [window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:true]; [[UIApplication sharedApplication] setStatusBarHidden:true];