Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // My GLSurfaceView.Renderer class
- @Override
- public void onDrawFrame(GL10 unused) {
- // draw background color
- GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
- Matrix.setLookAtM(this.modelViewMatrix, 0, 0, 0, this.eyeZ, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
- Matrix.multiplyMM(this.mvpMatrix, 0, this.projectionMatrix, 0, this.modelViewMatrix, 0);
- Square s = new Square();
- s.draw(this.mvpMatrix);
- }
- @Override
- public void onSurfaceChanged(GL10 unused, int width, int height) {
- GLES20.glViewport(0, 0, width, height);
- ratio = (float) width / height;
- Matrix.frustumM(this.projectionMatrix, 0, -ratio, ratio, -1, 1, 50, 70);
- }
- // My shaders
- public static final String vertexShaderCode =
- "uniform mat4 mvpMatrix;" +
- "attribute vec4 positionVector;" +
- "void main() {" +
- " gl_Position = positionVector * mvpMatrix;" +
- "}";
- public static final String fragmentShaderCode =
- "precision mediump float;" +
- "uniform vec4 colorVector;" +
- "void main() {" +
- " gl_FragColor = colorVector;" +
- "}";
- // Draw method for the square that I see
- public void draw(float[] mvpMatrix) {
- FloatBuffer vertexBuffer = this.calculateVertexBuffer();
- GLES20.glUseProgram(program);
- this.positionHandle = GLES20.glGetAttribLocation(program, "positionVector");
- GLES20.glEnableVertexAttribArray(this.positionHandle);
- GLES20.glVertexAttribPointer(
- this.positionHandle,
- this.coordsPerVertex,
- GLES20.GL_FLOAT,
- false,
- this.vertexStride,
- vertexBuffer
- );
- this.coloHandle = GLES20.glGetUniformLocation(this.program, "colorVector");
- GLES20.glUniform4fv(this.coloHandle, 1, this.color, 0);
- this.mvpMatrixHandle = GLES20.glGetUniformLocation(this.program, "mvpMatrix");
- UtilOpenGL.checkGlError("glGetUniformLocation");
- GLES20.glUniformMatrix4fv(this.mvpMatrixHandle, 1, false, mvpMatrix, 0);
- UtilOpenGL.checkGlError("glUniformMatrix4fv");
- GLES20.glDrawElements(
- GLES20.GL_TRIANGLES,
- drawOrder.length,
- GLES20.GL_UNSIGNED_SHORT,
- drawListBuffer
- );
- GLES20.glDisableVertexAttribArray(this.positionHandle);
- }
Advertisement
Add Comment
Please, Sign In to add comment