I'm trying to display the camera stream in a GLSurfaceView via a SurfaceTexture trasmitted to OpenGL ES 2.0 shaders.
I took inspiration from this post.
The image is complete but is not correctly displayed on my tablet. The screen seems divided in 2x2 parts. The image is displayed in the upper-left part whereas the other three parts are black.
I suspect that the problem comes from my usage of the transformation matrix returned by the sequence documented here
updateTexImage();
getTransformMatrix(...);
I transmit this matrix in the vertex shader to generate the texture coordinates for the fragment shader.
vertex shader:
attribute vec3 aPosition;
uniform mat4 uMvpTransform;
// Matrix retrieved by getTransformMatrix(...);
uniform mat4 uTexMatTransform;
varying vec2 vTexCoord;
void main(void)
{
gl_Position = uMvpTransform *vec4(aPosition.xyz, 1);
vec4 l_tex = uTexMatTransform*vec4(aPosition.xyz, 1);
vTexCoord=l_tex.xy;
}
fragment shader:
#extension GL_OES_EGL_image_external : require
varying mediump vec2 vTexCoord;
uniform samplerExternalOES uSampler;
void main(void)
{
mediump vec4 l_tex = texture2D(uSampler, vTexCoord);
gl_FragColor=l_tex;
}
The texture is attached to the following square:
// Image container
GLfloat l_vertices[] = {
-1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f };
Did anyone achieve something similar ?
Edited nov 3, 2012:
Correction of the vertex shader:
attribute vec3 aPosition;
attribute vec2 aTexCoord;
uniform mat4 uMvpTransform;
// Matrix retrieved by getTransformMatrix(...);
uniform mat4 uTexMatTransform;
varying vec2 vTexCoord;
void main(void)
{
gl_Position = uMvpTransform *vec4(aPosition.xyz, 1);
vec4 l_tex = uTexMatTransform*vec4(aTexCoord.xy,0, 1);
vTexCoord=l_tex.xy;
}
with:
// Texture
GLfloat l_texCoord[] = {
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f
};