cocos2d-x android background transprent

本文介绍了如何在Cocos2d-x GLSurfaceView中通过自定义Cocos2dxRenderer来实现透明的OpenGL背景效果,并通过修改onSurfaceCreated方法来优化渲染性能。

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

I had to add some code in Cocos2dxGLSurfaceView.java

in the initView method :

mRenderer = new Cocos2dxRenderer();
      setFocusableInTouchMode(true);
      setEGLConfigChooser(8, 8, 8, 8, 16, 0);
      setRenderer(mRenderer);
      getHolder().setFormat (PixelFormat.TRANSLUCENT);

and in the Cocos2dxRenderer

modify the onSurfaceCreated(GL10 gl, EGLConfig config) method:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {     
            nativeInit(Cocos2dxActivity.screenWidth, Cocos2dxActivity.screenHeight); 
            last = System.nanoTime();
            gl.glDisable(GL10.GL_DITHER);
            gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
                    GL10.GL_FASTEST);
             gl.glClearColor(0,0,0,0);
             gl.glEnable(GL10.GL_CULL_FACE);
             gl.glShadeModel(GL10.GL_SMOOTH);
             gl.glEnable(GL10.GL_DEPTH_TEST);
        }

With this I get a transparent openGLview background by the way I will make a post about my application done with cocos2dx for iPhone and android very soon :)



原文地址http://www.cocos2d-x.org/boards/6/topics/4804

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值