Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Texture widgets render OpenGL example

My Flutter app needs to display 3d model and allow user to rotate it. I implemented this via native views (ViewController & Activity) and C++ code for rendering, as next step I tried Texture widget to remove native views and use only Flutter. I managed to display OpenGL rendering on iOS via FlutterTexture, but don't understand how to implement on Android. Could you show any examples how to use OpenGL with SurfaceTexture and connect it to Texture widget?

like image 483
German Saprykin Avatar asked Mar 30 '18 14:03

German Saprykin


1 Answers

SurfaceTexture should be passed to eglCreateWindowSurface, while OpenGL stack is being configured.

I spent a while and built example project and article: https://github.com/mogol/opengl_texture_widget_example https://medium.com/@germansaprykin/opengl-with-texture-widget-f919743d25d9

private void initGL() {
    egl = (EGL10) EGLContext.getEGL();
    eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] version = new int[2];
    egl.eglInitialize(eglDisplay, version);

    EGLConfig eglConfig = chooseEglConfig();
    eglContext = createContext(egl, eglDisplay, eglConfig);

    eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture, null);

    egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
}
like image 124
German Saprykin Avatar answered Sep 18 '22 00:09

German Saprykin