Я использую код от https://github.com/d3kod/Texample2 для визуализации текста в OpenGL 2.0. Объяснение этого проекта можно найти по адресу: http://primalpond.wordpress.com/2013/02/26/rendering-text-in-opengl-2-0-es-on-android/OpenGL 2.0 ES 1281 Ошибка в glEnableVertexAttribArray
Этот код отлично работает на моем Android-устройстве Samsung Galaxy S3 4.1.2. Тем не менее, это не работает на моем Droid X, работающем под управлением Android 2.4.4, а у кого-то еще была проблема на Android 4.0 4.0 Onepad 940 (см. http://primalpond.wordpress.com/2013/02/26/rendering-text-in-opengl-2-0-es-on-android/#comment-89).
я получаю ошибку 1281 на линии: GLES20.glEnableVertexAttribArray(mColorHandle)
Я определил, что это происходит потому, что GL_MAX_VERTEX_ATTRIBS
на моем Droid X является только 8, и mColorHandle
устанавливается на 26. Когда я запускаю мое приложение на мой Samsung GS3, GL_MAX_VERTEX_ATTRIBS
равен 16, но mColorHandle
установлен в 0.
Так как с 26> 8, ошибка 1281 выбрасывается. Я не понимаю, почему Droid получает значение дескриптора 26 и GS3 получает 0.
Программа mProgram
установлена в этой строке в конструктор объекта:
mColorHandle = GLES20.glGetUniformLocation(mProgram.getHandle(), "u_Color");
Это где линия что создает ошибку:
void initDraw(float red, float green, float blue, float alpha) {
GLES20.glUseProgram(mProgram.getHandle()); // specify the program to use
// set color TODO: only alpha component works, text is always black #BUG
float[] color = {red, green, blue, alpha};
GLES20.glUniform4fv(mColorHandle, 1, color , 0);
GLES20.glEnableVertexAttribArray(mColorHandle);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); // Set the active texture unit to texture unit 0
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); // Bind the texture to this unit
// Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0
GLES20.glUniform1i(mTextureUniformHandle, 0);
//Log.i("error", "glerror3: " + GLES20.glGetError());
}
Редактировать
Это класс, который устанавливает программу:
public class BatchTextProgram extends Program {
private static final AttribVariable[] programVariables = {
AttribVariable.A_Position, AttribVariable.A_TexCoordinate, AttribVariable.A_MVPMatrixIndex
};
private static final String vertexShaderCode =
"uniform mat4 u_MVPMatrix[24]; \n" // An array representing the combined
// model/view/projection matrices for each sprite
+ "attribute float a_MVPMatrixIndex; \n" // The index of the MVPMatrix of the particular sprite
+ "attribute vec4 a_Position; \n" // Per-vertex position information we will pass in.
+ "attribute vec2 a_TexCoordinate;\n" // Per-vertex texture coordinate information we will pass in
+ "varying vec2 v_TexCoordinate; \n" // This will be passed into the fragment shader.
+ "void main() \n" // The entry point for our vertex shader.
+ "{ \n"
+ " int mvpMatrixIndex = int(a_MVPMatrixIndex); \n"
+ " v_TexCoordinate = a_TexCoordinate; \n"
+ " gl_Position = u_MVPMatrix[mvpMatrixIndex] \n" // gl_Position is a special variable used to store the final position.
+ " * a_Position; \n" // Multiply the vertex by the matrix to get the final point in
// normalized screen coordinates.
+ "} \n";
private static final String fragmentShaderCode =
"uniform sampler2D u_Texture; \n" // The input texture.
+ "precision mediump float; \n" // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
+ "uniform vec4 u_Color; \n"
+ "varying vec2 v_TexCoordinate; \n" // Interpolated texture coordinate per fragment.
+ "void main() \n" // The entry point for our fragment shader.
+ "{ \n"
+ " gl_FragColor = texture2D(u_Texture, v_TexCoordinate).w * u_Color;\n" // texture is grayscale so take only grayscale value from
// it when computing color output (otherwise font is always black)
+ "} \n";
@Override
public void init() {
super.init(vertexShaderCode, fragmentShaderCode, programVariables);
}
}
Я застрял в той же проблеме, вы нашли какое-либо решение? Я использую код Texample2, но, похоже, это ошибка в коде. – neur0tic