其他分享
首页 > 其他分享> > 多个OpenGL ES 2 Android渲染器

多个OpenGL ES 2 Android渲染器

作者:互联网

屏幕上可以一次显示多个渲染吗?像将android屏幕拆分为4个象限,并在每个象限上显示一个立方体?我认为它可能适用于OpenGL,但这是GLUT,并且基于Windows.我正在研究如何为android做它,但是我还没有遇到任何描述它的东西.这是创建渲染的主要活动.

public class MainActivity extends Activity
{

    private MyGLSurfaceView mGLView;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Create a GLSurfaceView instance and set it
        // as the ContentView for this Activity

        // "this" is the reference to activity
        mGLView = new MyGLSurfaceView(this);
        setContentView(mGLView);
    }

    @Override
    protected void onPause()
    {
        super.onPause();
        // The following call pauses the rendering thread.
        // If your OpenGL application is memory intensive,
        // you should consider de-allocating objects that
        // consume significant memory here.
        mGLView.onPause();
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        // The following call resumes a paused rendering thread.
        // If you de-allocated graphic objects for onPause()
        // this is a good place to re-allocate them.
        mGLView.onResume();
    }
}

class MyGLSurfaceView extends GLSurfaceView
{

    private final MyGLRenderer mRenderer;
    Context context;

    public MyGLSurfaceView(Context context)
    {
        super(context);

        this.context = context;
        // Create an OpenGL ES 2.0 context.
        setEGLContextClientVersion(2);

        // Set the Renderer for drawing on the GLSurfaceView
        Log.d("Test", "GL initialized");
        mRenderer = new MyGLRenderer(context);
        setRenderer(mRenderer);

        // Render the view only when there is a change in the drawing data
        setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    }
}

解决方法:

我不明白为什么只有一个GLSurfaceView无法做到这一点.通过调用glViewport将场景映射到该象限,可以将屏幕划分为四个象限.然后,您可以调用绘制函数,然后对每个后续象限重复此操作.

例:

glViewport(0, 0, width/2, height/2);
< render first quadrant >

glViewport(width / 2, 0, width / 2, height / 2);
< render second quadrant >

等等…

标签:android,opengl-es-2-0
来源: https://codeday.me/bug/20191030/1968575.html