glReadPixels() Problem in Android

Problems with Canvas, OpenGL, etc...

glReadPixels() Problem in Android

Postby sahiba202 » Tue Mar 15, 2011 8:18 pm

I am working on a project on Augmented Reality with Android. The code captures the camera video, finds the marker and displays a cube on top of it. After this a motion vector (in the form of pixels moved in the x and y direction) is found. What I need to do is read the pixels from the GL layer and draw them again after moving them by the distance specified by the motion vector.
The GL layer is specified using the GLSurfaceView class which is a transparent layer. The problem I am facing is that when I use glReadPixels() to read the pixels and convert it into a 480x800 array (nexus one screen resolution), I get 3 different portions of the cube instead of one.
I intend to move the pixels by the motion vector after this and use glDrawPixels() to put the pixels back into the frame buffer
Please help me with the interpretation of the same. Is there something I am missing while using glReadPixels and also if there is some other function that will help me achieve the same. I was thinking of using glBlitFrameBuffer() but this is not supported by the android GL10 class.
I have attached the part of the code where I am reading the pixels and changing them to a 2D matrix along with the image of the pixels I reconstructed using MatLab.
Any help will be greatly appreciated.

Code: Select all
   gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1);
         IntBuffer pixels = IntBuffer.allocate(384000);

         gl.glReadPixels(0, 0, 800, 480, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE ,pixels);
            File f = new File ("./mnt/sdcard/Sahiba_PixelData_" + flag + ".txt");
               FileWriter fw = new FileWriter(f);
               int pixelsArr [][] = new int [480][800];
               //int temp[] = pixels.array();
               int n=0;
               for(int i=0; i<480; i++){
                  for(int j=0; j<800; j++){
                     pixelsArr[i][j] = pixels.get(n);
                        //temp[n + pixels.arrayOffset()];
                     fw.write(pixelsArr[i][j] + " ");
                     //fw.write(pixels.get(n) + " ");
         Log.i("GLLayer", "Pixels reading and storing finished !!!");
         }catch(Exception e){
            Log.i("GLLayer","Exception = " +e);
477x800 rowWise.jpg
477x800 rowWise.jpg (42.42 KiB) Viewed 1090 times
Once Poster
Once Poster
Posts: 1
Joined: Tue Mar 15, 2011 8:14 pm


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

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests