首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CCRenderTexture,GL11ExtensionPack,Libgdx如何

CCRenderTexture,GL11ExtensionPack,Libgdx如何
EN

Stack Overflow用户
提问于 2012-11-12 03:17:30
回答 2查看 829关注 0票数 1

我目前工作的效果,如“小翅膀”http://www.raywenderlich.com/3857/how-to-create-dynamic-textures-with-ccrendertexture,并发现CCRenderTexture是解决方案。所以我想知道如何在android上实现这个效果,最后我找到了这个链接https://github.com/ZhouWeikuan/cocos2d/blob/master/cocos2d-android/src/org/cocos2d/opengl/CCRenderTexture.java --它显示了它的https://github.com/ZhouWeikuan/cocos2d/blob/master/cocos2d-android/src/org/cocos2d/opengl/CCRenderTexture.java

代码语言:javascript
复制
GL11ExtensionPack egl = (GL11ExtensionPack)CCDirector.gl;
        egl.glGetIntegerv(GL11ExtensionPack.GL_FRAMEBUFFER_BINDING_OES, oldFBO_, 0);
...

但在GLWrapperBase.java中,它显示

代码语言:javascript
复制
// Unsupported GL11ExtensionPack methods
public void glBindFramebufferOES (int target, int framebuffer) {
        throw new UnsupportedOperationException();
}

似乎gdx还没有实现这个功能。我想知道libgdx的相同特性是什么,或者如何在桌面上使用GL11ExtensionPack ~谢谢

EN

回答 2

Stack Overflow用户

发布于 2012-11-12 15:23:04

在libGDX中,您希望使用FrameBuffer对象来执行相当于"CCRenderTexture“的操作。FrameBuffer基本上允许您使用OpenGL命令绘制到屏幕外的缓冲区中,然后您可以稍后以纹理的形式显示该缓冲区的内容。见http://code.google.com/p/libgdx/wiki/OpenGLFramebufferObject。注意,只有当应用程序需要FrameBuffer es2.0时,OpenGL对象才可用。

根据您想要绘制的内容,您还可以查看libGDX中的libGDX类。这支持一些简单的运行时绘图操作(如线条、矩形和像素)。再一次,你的想法是你画到这个纹理,然后在屏幕上渲染得到的纹理稍后。这在OpenGL ES1.0中也是可用的。

FrameBuffer和Pixmap在安卓和桌面上都应该能很好地工作(我也相信GWT和iOS )。

注意,当你的应用程序暂时失去焦点时,安卓系统会发生什么(OpenGL上下文丢失会导致一些纹理内容消失)。

票数 1
EN

Stack Overflow用户

发布于 2016-06-25 08:02:33

代码语言:javascript
复制
    Question   :   CCRenderTexture,GL11ExtensionPack,Libgdx How TO
interpreted as :   In libgdx, how to create dynamic texture.
    Answer     :   Use a private render function to draw in a private frame
    Example framework:
    ==================
    package com.badlogic.gdx.tests.bullet;

    /**
    Question   :   CCRenderTexture,GL11ExtensionPack,Libgdx How TO
interpreted as :   In libgdx, how to create dynamic texture?
    Answer     :   Use a private render function to draw in a private frame buffer
                convert the frame bufder to Pixmap, create Texture.
    Author  :   Jon Goodwin
    **/

    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.Pixmap;
    ...//(ctrl-shift-o) to auto-load imports in Eclipse


    public class BaseBulletTest extends BulletTest
    {
    //class variables
    =================
    public Texture           texture     = null;//create this
    public Array<Disposable> disposables = new Array<Disposable>();
    public Pixmap            pm          = null;
    //---------------------------
        @Override
        public void create ()
        {
            init();
        }
    //---------------------------
        public static void init ()
        {
            if(texture == null) texture(Color.BLUE, Color.WHITE);
            TextureAttribute ta_tex     = TextureAttribute.createDiffuse(texture);
            final Material material_box = new Material(ta_tex, ColorAttribute.createSpecular(1, 1, 1, 1),
                                                       FloatAttribute.createShininess(8f));
            final long attributes1      = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
            final Model boxModel = modelBuilder.createBox(1f, 1f, 1f, material_box, attributes1);
            ...
        }
    //---------------------------
        public Texture texture(Color fg_color, Color bg_color)
        {
            Pixmap pm = render( fg_color, bg_color );
            texture = new Texture(pm);//***here's your new dynamic texture***
            disposables.add(texture);//store the texture
        }
    //---------------------------
        public Pixmap render(Color fg_color, Color bg_color)
        {
            int width = Gdx.graphics.getWidth();
            int height = Gdx.graphics.getHeight();

            SpriteBatch spriteBatch = new SpriteBatch();

            m_fbo = new FrameBuffer(Format.RGB565, (int)(width * m_fboScaler), (int)(height * m_fboScaler), false);
            m_fbo.begin();
            Gdx.gl.glClearColor(bg_color.r, bg_color.g, bg_color.b, bg_color.a);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            Matrix4 normalProjection = new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(),  Gdx.graphics.getHeight());
            spriteBatch.setProjectionMatrix(normalProjection);

            spriteBatch.begin();
            spriteBatch.setColor(fg_color);
            //do some drawing ***here's where you draw your dynamic texture***
            ...
            spriteBatch.end();//finish write to buffer

            pm = ScreenUtils.getFrameBufferPixmap(0, 0, (int) width, (int) height);//write frame buffer to Pixmap

            m_fbo.end();
    //      pm.dispose();
    //      flipped.dispose();
    //      tx.dispose();
            m_fbo.dispose();
            m_fbo = null;
            spriteBatch.dispose();
    //      return texture;
            return pm;
        }
    //---------------------------
    }//class BaseBulletTest
    //---------------------------
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13337936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档