Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- on gl surface creation --
- GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- GLES20.glFrontFace(GLES20.GL_CW);
- GLES20.glCullFace(GLES20.GL_BACK);
- GLES20.glEnable(GLES20.GL_CULL_FACE);
- GLES20.glDepthFunc(GLES20.GL_LEQUAL);
- GLES20.glEnable(GLES20.GL_DEPTH_TEST);
- GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
- GLES20.glEnable(GLES20.GL_BLEND);
- -- on gl surface changed --
- GLES20.glViewport(0, 0, width, height);
- -- activating 'material' before draw --
- GLES20.glUseProgram(shaderId);
- checkGlError("glUseProgram");
- GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
- GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
- -- on draw --
- alphaHandle = GLES20.glGetAttribLocation(material.getShader(), "aAlpha");
- checkGlError("glGetAttribLocation aAlpha");
- if (alphaHandle == GL_ERROR)
- {
- throw new RuntimeException("Could not get attribute location for aAlpha");
- }
- GLES20.glVertexAttrib1f(alphaHandle, alpha);
- checkGlError("glVertexAttrib1f alphaHandle");
- /*
- * GRID POSITION
- */
- positionHandle = GLES20.glGetAttribLocation(material.getShader(), "aPosition");
- checkGlError("glGetAttribLocation aPosition");
- if (positionHandle == GL_ERROR)
- {
- throw new RuntimeException("Could not get attribute location for uPosition");
- }
- GLES20.glVertexAttrib3f(positionHandle, position.x, position.y, position.z);
- checkGlError("glVertexAttrib3f positionHandle");
- /*
- * VERTICES
- */
- vertexHandle = GLES20.glGetAttribLocation(material.getShader(), "aVertex");
- checkGlError("glGetAttribLocation aVertex");
- if (vertexHandle == GL_ERROR)
- {
- throw new RuntimeException("Could not get attrib location for aVertex");
- }
- GLES20.glEnableVertexAttribArray(vertexHandle);
- checkGlError("glEnableVertexAttribArray vertexHandle");
- mesh.getVertexBuffer().position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
- GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mesh.getVertexBuffer());
- checkGlError("glVertexAttribPointer vertexHandle");
- /*
- * TEXTURE COORDS
- */
- textureHandle = GLES20.glGetAttribLocation(material.getShader(), "aTextureCoord");
- checkGlError("glGetAttribLocation aTextureCoord");
- if (textureHandle == GL_ERROR)
- {
- throw new RuntimeException("Could not get attrib location for aTextureCoord");
- }
- GLES20.glEnableVertexAttribArray(textureHandle);
- checkGlError("glEnableVertexAttribArray textureHandle");
- mesh.getVertexBuffer().position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
- GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mesh.getVertexBuffer());
- checkGlError("glVertexAttribPointer textureHandle");
- /*
- * MATRICES
- */
- mvpMatrixHandle = GLES20.glGetUniformLocation(material.getShader(), "uMVPMatrix");
- checkGlError("glGetUniformLocation uMVPMatrix");
- if (mvpMatrixHandle == GL_ERROR)
- {
- throw new RuntimeException("Could not get attrib location for uMVPMatrix");
- }
- Matrix.setIdentityM(mMatrix, 0);
- GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, DroidGL.getActiveCamera().getModelViewProjectionMatrix(mMatrix), 0);
- /*
- * DRAW
- */
- GLES20.glDrawElements(GLES20.GL_TRIANGLES, mesh.getNumIndices(), GLES20.GL_UNSIGNED_SHORT, mesh.getIndexBuffer());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement