/*
* Copyright (C) Winson Chiu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cw.kop.autobackground;
import android.opengl.GLES20;
public class GLShaders {
public static final String VERTEX_SHADER =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"attribute vec2 aTexCoords;" +
"varying vec2 vTexCoords;" +
"void main() {" +
" gl_Position = uMVPMatrix * vPosition;" +
" vTexCoords = aTexCoords;" +
"}";
public static final String FRAGMENT_SHADER =
"precision mediump float;" +
"varying vec2 vTexCoords;" +
"uniform float opacity;" +
"uniform sampler2D sTexture;" +
"void main() {" +
" gl_FragColor = texture2D(sTexture, vTexCoords);" +
" gl_FragColor.a *= opacity;" +
"}";
public static int loadShader(int type, String shaderCode) {
// create a vertex shader type (GLES20.GL_VERTEX_SHADER)
// or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
int shader = GLES20.glCreateShader(type);
// add the source code to the shader and compile it
GLES20.glShaderSource(shader, shaderCode);
GLES20.glCompileShader(shader);
// return the shader
return shader;
}
}