在openGl android(Wear)中绘制基于图像的纹理

时间:2016-01-26 05:26:54

标签: android opengl-es wear-os

我在android中使用opengl绘制基于图像的纹理,但是部分绘制的图像仅在下面显示     enter image description here

我的编码

 @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";

需要一些帮助才能做到这一点。温馨地指导我一个简单的方法我是android和opengl的新手....

1 个答案:

答案 0 :(得分:2)

将纹理坐标更改为

 {-1.0f, 1.0f, 0,0 ,
 1.0f, 1.0f, 1,0, 
-1.0f,-1.0f, 0,1 ,
1.0f, -1.0f, 1,1