Draw an Image based texture in openGl android(Wear)

馋奶兔 提交于 2019-12-24 01:36:09

问题


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

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....


回答1:


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 


来源:https://stackoverflow.com/questions/35007529/draw-an-image-based-texture-in-opengl-androidwear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!