0
我正在學習OpenGL ES 2 for Android的一本快速入門指南,學習opengl es 2.0 for android的教程。我在第3.5節,我的「編譯」代碼不會編譯。我已經檢查並進行了雙重檢查,但是我的代碼與本書相匹配。我搜索了SO和其他網站,但它似乎只是我有這個代碼有問題。我已經嘗試過使用AVD和jellybean物理設備,但我總是得到Compilation of shader failed
以下是我正在編譯的代碼。這個用於android的opengl es 2.o代碼有什麼問題嗎?
頂點編碼:
attribute vec4 a_Position;
void main(){
gl_Position = a_Position;
}
片段編碼:
precision mediump float;
uniform vec4 u_Color;
void main(){
gl_FragColor = u_Color;
}
助手類定位該資源並編譯的OpenGL的代碼:
public class ShaderHelper {
private static final String TAG = "ShaderHelper";
public static int compileVertexShader(String shaderCode){
return compileShader(GL_VERTEX_SHADER, shaderCode);
}
public static int compileFragmentShader(String shaderCode){
return compileShader(GL_FRAGMENT_SHADER, shaderCode);
}
public static int compileShader(int type, String shaderCode){
final int shaderObjectId = glCreateShader(type);
if(shaderObjectId == 0){
if(LoggerConfig.ON){
Log.w(TAG, "Could not create new shader.");
}
}
final int[] compileStatus = new int[1];
glGetShaderiv(shaderObjectId, GL_COMPILE_STATUS, compileStatus, 0);
if(LoggerConfig.ON){
Log.v(TAG, "Results of compiling source:" + "\n" + shaderCode + "\n:" + glGetShaderInfoLog(shaderObjectId));
}
if(compileStatus[0] == 0){
glDeleteShader(shaderObjectId);
if(LoggerConfig.ON){
Log.w(TAG, "Compilation of shader failed."); <--This is where I get notification that the code did not compile...
}
return 0;
}
return shaderObjectId;
}
public static int linkProgram(int vertexShaderId, int fragmentShaderId){
final int programObjectId = glCreateProgram();
if(programObjectId == 0){
if (LoggerConfig.ON){
Log.w(TAG, "Could not create new program.");
}
return 0;
}
glAttachShader(programObjectId, vertexShaderId);
glAttachShader(programObjectId, fragmentShaderId);
final int[] linkStatus = new int[1];
glGetProgramiv(programObjectId, GL_LINK_STATUS, linkStatus, 0);
if(LoggerConfig.ON){
Log.v(TAG, "Results of linking program:\n" + glGetProgramInfoLog(programObjectId));
}
if(linkStatus[0] == 0){
glDeleteProgram(programObjectId);
if(LoggerConfig.ON){
Log.w(TAG, "Linking of program failed.");
}
return 0;
}
return programObjectId;
}
public static boolean validateProgram(int programObjectId){
glValidateProgram(programObjectId);
final int[] validateStatus = new int[1];
glGetProgramiv(programObjectId, GL_VALIDATE_STATUS, validateStatus, 0);
Log.v(TAG, "Results of validating program: " + "\nLog:" + glGetProgramInfoLog(programObjectId));
return validateStatus[0] != 0;
}
}
是的,有很多電話缺失。 'glShaderSource()','glCompileShader()'等 – 2014-09-02 22:49:03