2

Good day sirs.

I'm having problem in displaying a bitmap that comes from an openGL in my own imageView.

First, I'm creating an openGL with 3D objects inside (Like cubes, sphere etc.)

Then, I convert the openGL onDraw view to a bitmap (i use this codes)

public static Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, GL10 gl)
        throws OutOfMemoryError {
    int bitmapBuffer[] = new int[w * h];
    int bitmapSource[] = new int[w * h];
    IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
    intBuffer.position(0);

    try {
        gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer);
        int offset1, offset2;
        for (int i = 0; i < h; i++) {
            offset1 = i * w;
            offset2 = (h - i - 1) * w;
            for (int j = 0; j < w; j++) {
                int texturePixel = bitmapBuffer[offset1 + j];
                int blue = (texturePixel >> 16) & 0xff;
                int red = (texturePixel << 16) & 0x00ff0000;
                int pixel = (texturePixel & 0xff00ff00) | red | blue;
                bitmapSource[offset2 + j] = pixel;
            }
        }
    } catch (GLException e) {
        return null;
    }

    return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
}

Well, it captures the view of the onDraw and turn it to bitmap, but what I need is to make the openGL a background process, convert its view to a bitmap, the display the bitmap in an imageview in my main activity.

I removed the

setContentView(ourSurfaceView)

in my mainActivity but after removing it and changing with my layout.xml the bitmap I'm creating from openGL is not functioning. (Sorry for my english)

THanks in advanced. :)

CheeMa
  • 41
  • 1
  • 4

1 Answers1

0

With 4.2(API Level 17) EGL got introduced into the android sdk. EGL makes offscreen rendering possible. Check out this answer: https://stackoverflow.com/a/13504396/1404216

Community
  • 1
  • 1
xeed
  • 925
  • 8
  • 22