Run Android OpenGL in Background as Rendering Resource for App?

后端 未结 2 1646
-上瘾入骨i
-上瘾入骨i 2020-12-08 16:48

I want to run an Android OpenGL-ES surface in the background of my app to provide dynamic graphical resources (bitmaps, etc.) for the application. The OpenGl GLSurfaceView i

2条回答
  •  失恋的感觉
    2020-12-08 17:46

    For what you're trying to do, you should skip the GLSurfaceView entirely. Since you just want to do some OpenGL offscreen rendering, you can make use of an EGL pixel buffer and convert it to a bitmap. See this thread on anddev for a solution. I've used it very successfully in a few of my apps.

    The implementation towards the bottom of that thread is a bit buggy, since it does some very simple EGL choosing. I'd recommend implementing a more robust chooser, which you can find in Robert Green's GLWallpaperService, if you'd like.

    Another change I ended up making was to remove the vertical pixel mirroring. I just ended up flipping my viewport in onSurfaceCreate, rather than manually flip rendered pixels when writing to the bitmap.

    Good luck!

提交回复
热议问题