ios版本下,在AppController.mm中设置multiSampling和numberOfSamples,如下
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: YES
numberOfSamples: 4 ];
android版本下,在cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dActivity.java中加入EGL_SAMPLE_BUFFERS和EGL_SAMPLES,如下
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
int[] EGLattribs = {
EGL10.EGL_RED_SIZE, configAttribs[0],
EGL10.EGL_GREEN_SIZE, configAttribs[1],
EGL10.EGL_BLUE_SIZE, configAttribs[2],
EGL10.EGL_ALPHA_SIZE, configAttribs[3],
EGL10.EGL_DEPTH_SIZE, configAttribs[4],
EGL10.EGL_STENCIL_SIZE,configAttribs[5],
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_SAMPLE_BUFFERS,1,
EGL10.EGL_SAMPLES,8,
EGL10.EGL_NONE
};
原理,开启多重采样以达到扛锯齿。缺点,对于性能要求高,在模拟机上非常卡,真机测试还行。
本文介绍在iOS和Android平台使用Cocos2d-x引擎时,如何通过设置multiSampling和numberOfSamples参数来实现多重采样抗锯齿效果。此技术能显著改善图形边缘平滑度,但对设备性能要求较高,可能导致模拟器运行缓慢。
5353

被折叠的 条评论
为什么被折叠?



