public SimpleRenderer() { mWindowWidth = 0; mWindowHeight = 0; string vs = @"attribute vec4 aPosition; void main() { gl_Position = aPosition; }"; string fs = @"precision mediump float; void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; mProgram = CompileProgram(vs, fs); mPositionAttribLocation = Gles.glGetAttribLocation(mProgram, "aPosition"); if (UseBufferMethod) { Gles.glGenBuffers(1, out mVertexPositionBuffer); Gles.glThrowError(); Gles.glBindBuffer(Gles.GL_ARRAY_BUFFER, mVertexPositionBuffer); Gles.glThrowError(); Gles.glBufferData(Gles.GL_ARRAY_BUFFER, mVertexPositions, Gles.GL_STATIC_DRAW); Gles.glThrowError(); } }
public SimpleRenderer() { mWindowWidth = 0; mWindowHeight = 0; mDrawCount = 0; // Vertex Shader source string vs = @"uniform mat4 uModelMatrix; uniform mat4 uViewMatrix; uniform mat4 uProjMatrix; attribute vec4 aPosition; attribute vec4 aColor; varying vec4 vColor; void main() { gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * aPosition; vColor = aColor; }"; // Fragment Shader source string fs = @"precision mediump float; varying vec4 vColor; void main() { gl_FragColor = vColor; }"; // Set up the shader and its uniform/attribute locations. mProgram = CompileProgram(vs, fs); mPositionAttribLocation = Gles.glGetAttribLocation(mProgram, "aPosition"); mColorAttribLocation = Gles.glGetAttribLocation(mProgram, "aColor"); mModelUniformLocation = Gles.glGetUniformLocation(mProgram, "uModelMatrix"); mViewUniformLocation = Gles.glGetUniformLocation(mProgram, "uViewMatrix"); mProjUniformLocation = Gles.glGetUniformLocation(mProgram, "uProjMatrix"); // Then set up the cube geometry. GLfloat[] vertexPositions = new[] { -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, }; Gles.glGenBuffers(1, out mVertexPositionBuffer); Gles.glBindBuffer(Gles.GL_ARRAY_BUFFER, mVertexPositionBuffer); Gles.glBufferData(Gles.GL_ARRAY_BUFFER, vertexPositions, Gles.GL_STATIC_DRAW); GLfloat[] vertexColors = new[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, }; Gles.glGenBuffers(1, out mVertexColorBuffer); Gles.glBindBuffer(Gles.GL_ARRAY_BUFFER, mVertexColorBuffer); Gles.glBufferData(Gles.GL_ARRAY_BUFFER, vertexColors, Gles.GL_STATIC_DRAW); GLshort[] indices = new GLshort[] { 0, 1, 2, // -x 1, 3, 2, 4, 6, 5, // +x 5, 6, 7, 0, 5, 1, // -y 0, 4, 5, 2, 7, 6, // +y 2, 3, 7, 0, 6, 4, // -z 0, 2, 6, 1, 7, 3, // +z 1, 5, 7, }; Gles.glGenBuffers(1, out mIndexBuffer); Gles.glBindBuffer(Gles.GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer); Gles.glBufferData(Gles.GL_ELEMENT_ARRAY_BUFFER, indices, Gles.GL_STATIC_DRAW); }