Now, I'm trying to write MapView of GoogleMaps Android API to OpenGLES2.0 texture, and make the texture be displayed with OpenGL in Android Project.
But so far, I couldn't do that. It displays only Google Logo and background. The map isn't displayed.
What I tried are the following. 1) To make OpenGL texture. 2) To make SubClass of MapView, and write the Texture using overridden draw method. 3) To set the display area and rendered the texture in every frame, using GLSurfaceView.Renderer inherited class.
Do you know how to write GoogleMap to OpenGL Texture, and render that?
The following are the parts of my code have relevance to this matter.
- It is the overridden draw method of MapView SubClass
@Override
public void draw(Canvas canvas){
final Canvas surfaceCanvas = surface.lockCanvas( null );
super.draw(surfaceCanvas);
surface.unlockCanvasAndPost( surfaceCanvas );
}
- GLSurfaceView.Renderer inherited Class(using Shader Class named GLES)
@Override
public void onSurfaceCreated(GL10 gl10,EGLConfig eglConfig) {
GLES.makeProgram();
GLES20.glEnableVertexAttribArray(GLES.positionHandle);
GLES20.glEnableVertexAttribArray(GLES.uvHandle);
GLES20.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,
GLES20.GL_ONE_MINUS_SRC_ALPHA);
uvBuffer=makeUVBuffer();
}
@Override
public void onSurfaceChanged(GL10 gl10,int w,int h) {
surface = null;
surfaceTexture = null;
textureId=createTexture();
GLES20.glViewport(0,0,w,h);
screenW=w;
screenH=h;
vertexBuffer0=makeVertexBuffer(50,50,200,200);
vertexBuffer1=makeVertexBuffer(50,300,300,300);
if(textureId > 0){
surfaceTexture = new SurfaceTexture( textureId );
surfaceTexture.setDefaultBufferSize( 1134, 1134);
GL20TextureEx1.surface = new Surface( surfaceTexture );
}
}
@Override
public void onDrawFrame(GL10 gl10) {
synchronized ( this ) {
surfaceTexture.updateTexImage();
}
GLES20.glClearColor(0.5f,1.0f,1.0f,0.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);
GLES20.glUniform1i(GLES.texHandle,0);
GLES20.glVertexAttribPointer(GLES.uvHandle,2,
GLES20.GL_FLOAT,false,0,uvBuffer);
GLES20.glVertexAttribPointer(GLES.positionHandle,3,
GLES20.GL_FLOAT,false,0,vertexBuffer0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,0,4);
GLES20.glVertexAttribPointer(GLES.positionHandle,3,
GLES20.GL_FLOAT,false,0,vertexBuffer1);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,0,4);
}