2

I am drawing an image based texture using opengl in android, But the image is drawn partially only shown below
enter image description here

my coding

 @Override
    public void onGlContextCreated() {
        super.onGlContextCreated();
        shaders = new ShadersDla();
        float[] vts = { // x, y, s, t.
                -1, 1, 1, 1, -1, 1, 0, 0, 1, -1, 1, 1, 1, 1, 1, 0

        };
        // AllocateDirect prevents the GC moving this memory.
        vtBuffer = ByteBuffer.allocateDirect(vts.length * 4)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        vtBuffer.put(vts);
    }  
 @Override
    public void onGlSurfaceCreated(int width, int height) {
        super.onGlSurfaceCreated(width, height);
        float aspectRatio = (float) width / height;
 float dist = .001f;
        Matrix.frustumM(projectionMatrix, 0,
                -aspectRatio * dist, aspectRatio * dist, // Left, right.
                -dist, dist, // Bottom, top.
                dist, 100); // Near, far.
   makeTexture();
    }

Shader

private static final String VERTEX_SHADER =
        // Pass in the modelview matrix as a constant.
        "uniform mat4 u_mvpMatrix;  \n"
                // Pass in the position and texture coordinates per vertex.
                + "attribute vec4 a_position;  \n"
                + "attribute vec2 a_texCoord;  \n"
                // Varyings are sent on to the fragment shader.
                + "varying vec2 v_texCoord;  \n"
+ "void main() {  \n"
                // Transform the vertex coordinate into clip coordinates.
                + "  gl_Position = u_mvpMatrix * a_position;  \n"
                // Pass through the texture coordinate.
                + "  v_texCoord = a_texCoord;  \n"
                + "}  \n";

Need some help to do this stuff.kindly guide me a easy way i'm new to android and opengl....

Ed.
  • 304
  • 2
  • 16
  • So how many vertex points do you have? Were you looking at a OpenGL sample which has quads vs OpenGL ES which has triangles? – Morrison Chang Jan 26 '16 at 05:35
  • The first two vertices have the same x/y coordinates. The texture coordinates look fishy, too, with two vertices (1st and 3rd) having the same texture coordinates. – Reto Koradi Jan 26 '16 at 05:56
  • could give me some sample or any link which has more explain about the texture coordinates ,as am new to android openGl – Ed. Jan 26 '16 at 06:31
  • 1
    This is an old question with a highly voted answer explaining texture coordinates: http://stackoverflow.com/questions/5532595/how-do-opengl-texture-coordinates-work. – Reto Koradi Jan 26 '16 at 06:53
  • Got the answer, i change the texture coordinates,, thank@Reto Koradi – Ed. Jan 26 '16 at 10:46

1 Answers1

2

Change the texture coordinates as

 {-1.0f, 1.0f, 0,0 ,
 1.0f, 1.0f, 1,0, 
-1.0f,-1.0f, 0,1 ,
1.0f, -1.0f, 1,1 
Edgar prabhu
  • 563
  • 3
  • 21