纹理单一颜色
English describe : android opengl textureview solid color
StackOverFlow推荐的错误排查
PS:(声明了属性,但没使用,debug时position为-1(测试时注意))
直接原因
纹理坐标赋值没有起效,实际上一直在重复纹理0,0坐标上的颜色
可能代码原因
- stackoverflow那个是属性赋值没有glEnableVertexAttribArray
- 对属性赋值时 VBO和FloatBuffer作为实参 两种方式不能混合使用
针对2的实验代码如下:
public class Triangle {
private final String vertexShaderCode =
// This matrix member variable provides a hook to manipulate
// the coordinates of the objects that use this vertex shader
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"attribute vec2 a_TexCoordinate;" +
"varying vec2 v_TexCoordinate;" +
"void main() {" +
// the matrix must be included as a modifier of gl_Position
// Note that the uMVPMatrix factor *must be first* in order
// for the matrix multiplication product to be correct.
" v_TexCoordinate = a_TexCoordinate;" +
" gl_Position = uMVPMatrix * vPosition;" +
"}";
private final String fragmentShaderCode =
"precision highp float;" +
"uniform vec4 vColor;" +
"uniform sampler2D u_Texture;" +
"varying vec2 v_TexCoordinate;" +
"void main() {" +
" gl_FragColor =