public MainView(Context context) : base(context) { mRenderer = new MainRenderer(this); SetEGLContextClientVersion(2); SetRenderer(mRenderer); this.RenderMode = Android.Opengl.Rendermode.WhenDirty; }
/** * Sets up the drawing object data for use in an OpenGL ES context. */ public Triangle() { // initialize vertex byte buffer for shape coordinates ByteBuffer bb = ByteBuffer.AllocateDirect( // (number of coordinate values * 4 bytes per float) triangleCoords.Length * 4); // use the device hardware's native byte order bb.Order(ByteOrder.NativeOrder()); // create a floating point buffer from the ByteBuffer vertexBuffer = bb.AsFloatBuffer(); // add the coordinates to the FloatBuffer vertexBuffer.Put(triangleCoords); // set the buffer to read the first coordinate vertexBuffer.Position(0); // prepare shaders and OpenGL program int vertexShader = MainRenderer.loadShader(GLES20.GlVertexShader, vertexShaderCode); int fragmentShader = MainRenderer.loadShader(GLES20.GlFragmentShader, fragmentShaderCode); mProgram = GLES20.GlCreateProgram(); // create empty OpenGL Program GLES20.GlAttachShader(mProgram, vertexShader); // add the vertex shader to program GLES20.GlAttachShader(mProgram, fragmentShader); // add the fragment shader to program GLES20.GlLinkProgram(mProgram); // create OpenGL program executables }
public MainView(Context context) : base(context) { mRenderer = new MainRenderer(this); SetEGLContextClientVersion(2); SetRenderer(mRenderer); this.RenderMode = Android.Opengl.Rendermode.WhenDirty; }
/** * Encapsulates the OpenGL ES instructions for drawing this shape. * * @param mvpMatrix - The Model View Project matrix in which to draw * this shape. */ public void draw(float[] mvpMatrix) { // Add program to OpenGL environment GLES20.GlUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.GlGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.GlEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.GlVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES20.GlFloat, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES20.GlGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES20.GlUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.GlGetUniformLocation(mProgram, "uMVPMatrix"); MainRenderer.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); MainRenderer.checkGlError("glUniformMatrix4fv"); // Draw the triangle GLES20.GlDrawArrays(GLES20.GlTriangles, 0, vertexCount); // Disable vertex array GLES20.GlDisableVertexAttribArray(mPositionHandle); }