Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android OpenGLES 1.x CameraPreview to Surfacetexture

I am trying to send the camera preview to a surfacetexture object and render it on a square. I have running code for GLES20 but didnt find anything for 1.x. Basically it should work like this, right?

// setup texture
gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
gl.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, ...);
...

// setup surfacetexture object
surface = new SurfaceTexture(textures[0]);
surface.setOnFrameAvailableListener(this);


// setup camera
mCamera = Camera.open(0);
Camera.Parameters param = mCamera.getParameters();
List<Size> psize = param.getSupportedPreviewSizes();
//find previewsize to match glsurface from renderer
param.setPreviewSize(psize.get(i).width, psize.get(i).height);
mCamera.setParameters(param);

// set the texture and start preview
mCamera.setPreviewTexture(surface);
mCamera.startPreview();


// in the "onFrameAvailable" handler, i switch a flag to mark a new frame
updateSurface = true;


// and in the renderloop i update and redraw
if (updateSurface) {
    surface.updateTexImage();
    updateSurface = false;
}
gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);

// Draw square
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBufferFloor);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

The square gets drawn but is completely white. I dont receive glErrors or other exceptions. The "onFrameAvailable" handler gets called too. If i use glTeximage with a loaded bitmap, it is correctly drawn on the square.

ANY ideas? Thank you!

like image 864
J-S Avatar asked Sep 02 '13 12:09

J-S


1 Answers

I'm facing the same problem. Maybe I'm wrong, but it seems that SurfaceTexture is not compatible with GLES10. Surface texture uses GL_TEXTURE_EXTERNAL_OES, thereby it a custom fragment shader that is able to use this texture ("#extension GL_OES_EGL_image_external : require ").

As glUseProgram(...), etc are not avaible in GLES10, we cannot use custom shaders.

As I said, maybe I'm wrong... Good luck

EDIT : I finaly get it to work. You should use "gl.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);"

like image 51
Nicolas Avatar answered Sep 27 '22 19:09

Nicolas