Using GLSurfaceView to render off-screen

Problems with Canvas, OpenGL, etc...

Using GLSurfaceView to render off-screen

Postby shashachu » Sat Aug 21, 2010 7:20 pm


I am new to Android development. I am investigating ways to render OpenGL off-screen to a bitmap (I want to dynamically render icons for use in my app), and I saw jsemler's post about using the EGL buffers to accomplish this (and I already sent him a PM), but I'm curious why my approach doesn't work.

I know that you can use View.getDrawingCache() to grab a bitmap of a view or control, but when I try the same on a GLSurfaceView, I get a NullPointerException.

Why does this work:
Code: Select all
Button b = new Button(context);
b.setText("Hello World");
b.layout(0, 0, 100, 100);
Bitmap bitmap = Bitmap.createBitmap(b.getDrawingCache());

And this doesn't:
Code: Select all
GLSurfaceView newView = new GLSurfaceView(this);
newView.setRenderer(new MyRenderer());
newView.layout(0, 0, 100, 100);
newView.buildDrawingCache(); // This line crashes
Bitmap b = Bitmap.createBitmap(newView.getDrawingCache());

Here is the stack trace from the exception:
at android.view.SurfaceView.updateWindow(
at android.view.SurfaceView.dispatchDraw(
at android.view.View.buildDrawingCache(
at android.view.View.buildDrawingCache(
at android.view.View.performClick(
at android.view.View.onTouchEvent(
at android.widget.TextView.onTouchEvent(
at android.view.View.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(

(This stack trace is from when I was calling the code from a button click, but I also get a crash when I move the code into my activity's onCreate.)

Maybe I'm just trying to do something crazy, but this seems like an extremely convenient way to render 3D to an off-screen texture if I can get this working.

Sha Sha
Posts: 3
Joined: Fri Aug 20, 2010 4:50 pm


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests