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?
Asked
Active
Viewed 2,950 times
7
-
It's not quite a full OpenGL example, but one of Flutter's integration tests includes the use of SurfaceTexture: https://github.com/flutter/flutter/blob/f407871cb908a3e18e1e03f15a9172982e710786/dev/integration_tests/external_ui/android/app/src/main/java/io/flutter/externalui/MainActivity.java – RedBrogdon Apr 03 '18 at 18:26
1 Answers
7
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);
}

German Saprykin
- 6,631
- 2
- 29
- 26
-
I successfully built an example based on yours. It worked, but I'm sturggling in rendering to the texture with glTexImage2D. Could you take a look? https://stackoverflow.com/questions/58531692/how-to-render-opengl-in-flutter-for-android – PPP Oct 26 '19 at 02:23