cocos2d-x颜色缓冲

本文详细介绍了Cocos2d-v0.99.4及更新版本中缓冲、颜色缓冲、深度缓冲、高资源模式、多点抽样的使用方法和配置细节,包括如何创建RGBA8颜色缓冲、深度缓冲,以及如何在不同设备上实现Retina Display。此外,还提供了初始化EAGLView和Director的完整示例代码,帮助开发者优化游戏或应用的渲染效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

导演
缓冲
信息支持cocos2d v0.99.4和更新的版本
颜色缓冲
这个默认的缓冲时RGB565.它是一个16位的缓冲器,没有alpha(应该是一种cpu架构).为了使用RGBA8颜色换chogn,你需要创建并初始化EAGLView
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                                                   pixelFormat:kEAGLColorFormatRGBA8];
kEAGLColorFormatRGBA8:创建一个RGBA8颜色缓冲(32位)
kEAGLColorFormatRGB565:创建一个RGB565颜色缓冲(16位)。更快的,但是没有alpha


深度缓冲
默认情况下,cocos2d不使用深度缓冲,但是你可以创建一个当你初始化EAGLView用一个16位或者24位深度缓冲
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                               pixelFormat:kEAGLColorFormatRGBA8
                                           depthFormat:GL_DEPTH_COMPONENT24_OES];
GL_DEPTH_COMPONENT24_OES:24位深度缓冲
GL_DEPTH_COMPONENT16_OES:16位深度缓冲
0:没有深度缓冲被创建


高资源
自从v0.99.4开始,导演可以设置颜色来呈递缓冲再高资源模型里:
// 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]];
从v0.99.5开始,开始支持视网膜屏幕显示:
// 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");
它是怎么工作的:
如果你有一台iphon4,显示方案是960*640


多点抽样,或者全屏Anti_Aliasing
多点抽样可以执行在所有的设备上,但是在MBX设备中表现的冲击力更剧烈
怎么使用它
不要使用CC_DIRECTOR_INIT() macro。可以用下面的例子作为一个简单的模型
- (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;
}
分享到:
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值