android - 布局内的 OpenGL View

标签 android opengl-es

如何设置包含 OpenGL View 的 xml 布局?正如我现在所做的那样,将 OpenGL View 设置为使用 setContentView() 的唯一 View 。但我想创建一个包含 OpenGL View 的 xml 布局。假设我想主要使用 OpenGL View ,底部有一个小的 TextView。

这可能吗?或者 OpenGL View 只能是唯一的 View 吗?

最佳答案

这就是我为粒子发射器所做的:扩展 GLSurfaceView 并使其成为我布局的一部分。注意:实现“ParticleRenderer”类来实现你想做的任何 openGL 事情

我的自定义 View :

public class OpenGLView extends GLSurfaceView
{

    //programmatic instantiation
    public OpenGLView(Context context)
    {
        this(context, null);
    }

    //XML inflation/instantiation
    public OpenGLView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public OpenGLView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs);

        // Tell EGL to use a ES 2.0 Context
        setEGLContextClientVersion(2);

        // Set the renderer
        setRenderer(new ParticleRenderer(context));
    }

}

在布局中...

<com.hello.glworld.particlesystem.OpenGLView
    android:id="@+id/visualizer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

粒子渲染是直接的......一些示例代码,参见:https://code.google.com/p/opengles-book-samples/source/browse/trunk/Android/Ch13_ParticleSystem/src/com/openglesbook/particlesystem/ParticleSystemRenderer.java

public class ParticleRenderer implements GLSurfaceView.Renderer
{
    public ParticleRenderer(Context context)
    {
        mContext = context;
    }

    @Override
    public void onDrawFrame(GL10 gl)
    {
        //DO STUFF
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height)
    {
        //DO STUFF
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config)
    {
        //DO STUFF
    }
}

关于android - 布局内的 OpenGL View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4126353/

相关文章:

android - Ubuntu 9.10 中的 Nexus One Android 调试

android - 如何为 MPAndroidChart BarChart 设置高度和宽度?

opengl - 优化渲染是否需要从前到后绘制?

android - 处理 Android 的纹理大小限制

android - 为什么Android找不到android.graphics.OpenGLContext?

android - 如何在 Android 中以编程方式更改字体大小?

android - 连接到多个音频 channel 时如何解决Android webRTC音频中的回声

android - 在具有位置依赖性的 View 上转换动画

c++ - 如何在 native 事件中创建 OpenGL ES 2 上下文?

android - 简单的 OpenGL 引擎