布局中的OpenGL视图

Esp*_*pen 9 android opengl-es

如何设置一个OpenGL视图所属的xml布局?正如我现在所做的那样,将OpenGL视图设置为setContentView()的唯一视图.但我想创建一个包含OpenGL视图的xml布局.让我们说我想主要是OpenGL视图,底部是一个小的TextView.

这甚至可能吗?或者OpenGL视图只能是唯一的视图吗?

Som*_*ere 8

这就是我为粒子发射器所做的:扩展GLSurfaceView并使其成为我布局的一部分.注意:实现"ParticleRenderer"类来实现您想要做的任何openGL内容

我的自定义视图:

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));
    }

}
Run Code Online (Sandbox Code Playgroud)

并在布局中......

<com.hello.glworld.particlesystem.OpenGLView
    android:id="@+id/visualizer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
Run Code Online (Sandbox Code Playgroud)

粒子渲染很简单...对于一些示例代码,请参阅:https://code.google.com/p/opengles-book-sa​​mples/source/browse/trunk/Android/Ch13_ParticleSystem/src/com/openglesbook/粒子系统/ 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
    }
}
Run Code Online (Sandbox Code Playgroud)


Che*_*mon 7

您可以查看SurfaceView.它提供嵌入视图层次结构内部的专用绘图表面.另请参见使用画布绘图.