【发布时间】:2018-02-07 15:39:04
【问题描述】:
我的目标是在我的 Android 应用程序中使用 OpenGL 3.1 来显示纹理。 目前的问题是,着色器无法编译。
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;" +
"in vec4 vPosition;" +
"in vec2 vTextureCoordinate;" +
"out vec2 exTextureCoordinate;" +
"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.
" gl_Position = uMVPMatrix * vPosition;" +
" exTextureCoordinate = vTextureCoordinate;" +
"}";
private final String fragmentShaderCode =
"precision mediump float;" +
"uniform sampler2D texture;" +
"in vec2 exTextureCoordinate;" +
"out vec4 out_Color;" +
"void main() {" +
" out_Color = texture2D(texture, exTextureCoordinate);" +
"}";
想法:将模型视图矩阵连同在空间中的位置和纹理坐标一起传递给顶点着色器。纹理坐标通过fragmentShader进行着色,空间坐标通过Model-View Matrix进行变换。
编译着色器时出现以下错误代码:
E/ShaderCompile: Error compiling shader!
E/ShaderCompile:
ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only
ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only
ERROR: 0:1: 'out' : storage qualifier supported in GLSL ES 3.00 only
E/ShaderCompile: Error compiling shader!
E/ShaderCompile:
ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only
ERROR: 0:1: 'out' : storage qualifier supported in GLSL ES 3.00 only
我使用以下代码设置OpenGLES版本:
uses-feature android:glEsVersion="0x00030001" android:required="true"
setEGLContextClientVersion(3);
【问题讨论】:
标签: android opengl-es shader glsles