Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.

Buffers

Information valid for cocos2d v0.99.4 and newer

Color Buffer

The default color buffer is RGB565. It is a 16-bit buffer, without alpha. In order to use an RGBA8 color buffer, you need to create initialize the EAGLView with:

	EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
								   pixelFormat:kEAGLColorFormatRGBA8];
  • kEAGLColorFormatRGBA8: Creates an RGBA8 color buffer (32-bit)
  • kEAGLColorFormatRGB565: Creates an RGB565 color buffer (16-bit). Faster, but without alpha (default)

Depth Buffer

By default, cocos2d doesn't use a depth buffer, but you can create one when you initialize the EAGLView with a 16-bit or 24-bit depth buffer. eg:

	EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
				    	   pixelFormat:kEAGLColorFormatRGBA8
				           depthFormat:GL_DEPTH_COMPONENT24_OES];
  • GL_DEPTH_COMPONENT24_OES: 24-bit depth buffer
  • GL_DEPTH_COMPONENT16_OES: 16-bit depth buffer
  • 0: No depth buffer will be created

High Res

Since v0.99.4, the Director can set the color render buffer in High Res mode:

eg:

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if ([UIScreen instancesRespondToSelector:@selector(scale)])
	[director setContentScaleFactor:[[UIScreen mainScreen] scale]];

Since v0.99.5, the suggested way to enable Retina display is:

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
	CCLOG(@"Retina Display Not supported");

How does it work:

  • If you have an iPhone4, the screen resolution will be 960×640

MultiSampling, or Full Screen Anti-Aliasing

Multi sampling works on all devices, but on MBX devices the performance impact is severe.

How to enable it:

Don't use the CC_DIRECTOR_INIT() macro, but use the code from the sample below.

Sample

Complete sample of how to setup cocos2d:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	// Init the window
	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 
	// must be called before any other call to the director
	[CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
 
	// before creating any layer, set the landscape mode
	CCDirector *director = [CCDirector sharedDirector];
 
	// landscape orientation
	[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
 
	// set FPS at 60
	[director setAnimationInterval:1.0/60];
 
	// Display FPS: yes
	[director setDisplayFPS:YES];
 
	// Create an EAGLView with a RGB8 color buffer, and a depth buffer of 24-bits
	EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
		   pixelFormat:kEAGLColorFormatRGBA8                // RGBA8 color buffer
                   depthFormat:GL_DEPTH_COMPONENT24_OES   // 24-bit depth buffer
                   preserveBackbuffer:NO
                   sharegroup:nil //for sharing OpenGL contexts between threads
                   multiSampling:NO //YES to enable it
                   numberOfSamples:0 //can be 1 - 4 if multiSampling=YES
        ];
 
	// attach the openglView to the director
	[director setOpenGLView:glView];
 
	// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
	if( ! [director enableRetinaDisplay:YES] )
		CCLOG(@"Retina Display Not supported");
 
	// make the OpenGLView a child of the main window
	[window addSubview:glView];
 
	// make main window visible
	[window makeKeyAndVisible];	
 
	// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
	// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
	// You can change anytime.
	[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];	
 
	// create the main scene
	CCScene *scene = [...];
 
	// and run it!
	[director runWithScene: scene];
 
	return YES;
}
prog_guide/setup_buffers.txt · Last modified: 2011/01/19 17:24 by araker
Trace: 0_99_1 0_9_0_beta index flash_developers draw_update translations autorotation sample_games 0_8_2_rc0 setup_buffers
Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0