Log in or register to post comments

opengles 2.0 error 1282 after call glDrawElements(…) method

July 18, 2017 - 3:26am #1

I have some troubles with opengles 2.0. Currently I trying to display 3D teapot model without success. Method GLES20.glDrawElements generate opengl error with number 1282 and nothing is displayed on screen.

My draw method code:

public void draw(float[] tfMVPMatrix) {

    GLES20.glUseProgram(miProgramID);

    miVertexPositionHandle = GLES20.glGetAttribLocation(miProgramID, VertexShader.Variables.VERTEX_POSITION.getName());

    miVertexTexCoordsHandle = GLES20.glGetAttribLocation(miProgramID, VertexShader.Variables.VERTEX_TEXTURE_CORDS.getName());

    miVertexNormalsHandle = GLES20.glGetAttribLocation(miProgramID, VertexShader.Variables.VERTEX_NORMALS.getName());

    miProjectionMatrixHandle = GLES20.glGetUniformLocation(miProgramID, VertexShader.Variables.MVP_MATRIX.getName());

    miColorHandle = GLES20.glGetUniformLocation(miProgramID, FragmentShader.Variables.COLOR.getName());

    GLES20.glEnableVertexAttribArray(miVertexPositionHandle);

    GLES20.glVertexAttribPointer(miProgramID, 3, GLES20.GL_FLOAT, false, 3 * Float.SIZE, moVertBuff);

    GLES20.glEnableVertexAttribArray(miVertexTexCoordsHandle);

    GLES20.glVertexAttribPointer(miProgramID, 2, GLES20.GL_FLOAT, false, 2 * Float.SIZE, moTexCoordBuff);

    GLES20.glEnableVertexAttribArray(miVertexNormalsHandle);

    GLES20.glVertexAttribPointer(miProgramID, 3, GLES20.GL_FLOAT, false, 3 * Float.SIZE, moNormBuff);

    GLES20.glUniform4fv(miColorHandle, 1, COLOR, 0);

    GLES20.glUniformMatrix4fv(miProjectionMatrixHandle, 1, false, tfMVPMatrix, 0);

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, miIndicesNumber, GLES20.GL_UNSIGNED_SHORT, moIndBuff); // opengl error 1282

    GLES20.glDisableVertexAttribArray(miVertexPositionHandle);

    GLES20.glDisableVertexAttribArray(miVertexTexCoordsHandle);

    GLES20.glDisableVertexAttribArray(miVertexNormalsHandle);

}

Vertex shader code:

attribute vec4 vPosition;

attribute vec4 vNormal;

attribute vec2 vTexture;

varying vec2 texCoord;

varying vec4 normal;

uniform mat4 uMVPMatrix;

void main() {

    gl_Position = uMVPMatrix * vPosition;

    normal = vNormal;

    texCoord = vTexture;

}

Fragment shader code:

precision mediump float;

varying vec4 normal;

uniform vec4 vColor;

void main() {

    gl_FragColor = vColor;

}

My renderer code:

public class MyRenderer implements GLSurfaceView.Renderer {

private int GLProgramID;

private Demo3DObj oDemoTeapot;

private final float[] mMVPMatrix = new float[16];

private final float[] mProjectionMatrix = new float[16];

private final float[] mViewMatrix = new float[16];

private float fRatio;

@Override

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

    GLProgram oProgram = new GLProgram();

    GLProgramID = oProgram.build();

    oDemoTeapot = new Demo3DObj(GLProgramID);

    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

}

@Override

public void onSurfaceChanged(GL10 gl, int width, int height) {

    GLES20.glViewport(0, 0, width, height);

    fRatio = (float)width/height;

    Matrix.frustumM(mProjectionMatrix, 0, -fRatio, fRatio, -1, 1, 3, 7);

}

@Override

public void onDrawFrame(GL10 gl) {

    Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    oDemoTeapot.draw(mMVPMatrix);

}

}

Here is method, which is used to create moIndBuff:

private Buffer fillBufferI(int[] oContainer) {

    ByteBuffer bb = ByteBuffer.allocateDirect(2 * oContainer.length);

    bb.order(ByteOrder.LITTLE_ENDIAN);

    for (int s : oContainer)

        bb.putInt(s);

    bb.rewind();

    return bb;

}

I'm new in opengles world and I do not have any idea what can be wrong here. Can anybody help me solve this problem? What should I change here to display my model?

Log in or register to post comments