3

For an application i want to render things in background even when the app is not currently displayed. The official docs write to open a GLcontext via a GLSurfaceView. For not displaying graphics and rendering into another target there seems not to be a real solution.

So the Question is how to create a GL-context without GLSurfaceView in Android?

Use case: Record a video and add current time as text directly into video. For that CPU-based image-manipulation is simply to slow to be performed live. At least if the video should be also displayed while recording. OpenGL could render everything simply into a Framebuffer/Renderbuffer.

michi.0x5d
  • 959
  • 9
  • 13
  • What you could is overlay a translucent GLSurfaceView on top of the view which is playing the video. You would display the text with OpenGL in the GLSurfaceView, being carefull of setting correct alpha component, then OS would take care of compositing the two. – VB_overflow Aug 17 '15 at 13:37

2 Answers2

9

You don't have to use GLSurfaceView to do OpenGL rendering. If you look at the source code, you can see that it's only using only publicly available APIs. It is merely a convenience class that makes the most common uses of OpenGL under Android (using OpenGL to draw the content of a view) very easy. If your use case is different then you just... don't use it.

The API you use for creating contexts and rendering surfaces more directly is EGL. There are two versions of it available in the Android Java frameworks: EGL10 and EGL14. EGL10 is very old, and I would strongly recommend using EGL14.

The EGL calls are not really documented in the Android SDK documentation, but you can use the man pages on www.khronos.org to see the calls explained.

Using EGL directly, you can create a context and an off-screen rendering surface that will allow you to use OpenGL without any kind of view.

I posted complete code showing how to create a context with an off-screen rendering surface in a previous answer here: GLES10.glGetIntegerv returns 0 in Lollipop only.

Community
  • 1
  • 1
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
0

Already answered here and here

I think the most simple is what is described in second link when they say :

set it's view size 1pixel&1pixel, put it visible(user cannot see it) and in OnDraw bind FBO to the main texture and render it

So you would still create a GLSurfaceView (just to get a context) but you would make it 1x1 and invisible.

Or you could use a translucent GLSurfaceView as suggested in my comment (I am not sure this will work on any device, this seems to be a bit tricky to setup).

Community
  • 1
  • 1
VB_overflow
  • 1,763
  • 11
  • 15
  • Your way creating a small pseudo-invisible view is interesting but not suitable - since it requires an activity running. Your first link is better - since it does not require any view. Rendering can happen for example in a service. So im giving a +1 but @reto-koradi gets the acception since he describes more details about creating the context (which was the question). – michi.0x5d Aug 18 '15 at 19:37