/// <summary> /// Raises the draw frame event. /// </summary> /// <param name="gl">Gl.</param> public void OnDrawFrame(IGL10 gl) { // Replace the current matrix with the identity matrix gl.GlMatrixMode(GL10.GlProjection); gl.GlLoadIdentity(); // OpenGL docs gl.GlOrthof(_left, _right, _bottom, _top, -1, 1); for (int idx = 0; idx < _triangles.Count; idx++) { gl.GlVertexPointer(3, GL10.GlFloat, 0, _triangles[idx].Vertices); gl.GlEnableClientState(GL10.GlVertexArray); gl.GlColorPointer(4, GL10.GlUnsignedByte, 0, _triangles[idx].Colors); gl.GlEnableClientState(GL10.GlColorArray); gl.GlDrawArrays(GL10.GlTriangleStrip, 0, _triangles[idx].Count); } for (int idx = 0; idx < _lines.Count; idx++) { gl.GlVertexPointer(3, GL10.GlFloat, 0, _lines[idx].Vertices); gl.GlEnableClientState(GL10.GlVertexArray); SimpleColor color = new SimpleColor() { Value = _lines[idx].Color }; gl.GlColor4f(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); gl.GlLineWidth(_lines [idx].Width); gl.GlDrawArrays(GL10.GlLineStrip, 0, _lines[idx].Count); } }
public void Draw(IGL10 gl) { gl.GlFrontFace(GL10.GlCw); gl.GlVertexPointer(3, GL10.GlFixed, 0, mVertexBuffer); gl.GlColorPointer(4, GL10.GlFixed, 0, mColorBuffer); gl.GlDrawElements(GL10.GlTriangles, 36, GL10.GlUnsignedByte, mIndexBuffer); }
public override void Present(float deltaTime) { IGL10 gl = _glGraphics.GL10; gl.GlViewport(0, 0, _glGraphics.Width, _glGraphics.Height); gl.GlClearColor(0, 0, 0, 1); gl.GlClear(GL10.GlColorBufferBit); gl.GlMatrixMode(GL10.GlProjection); gl.GlLoadIdentity(); gl.GlOrthof(0, 540, 0, 960, 1, -1); gl.GlEnable(GL10.GlTexture2d); gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlEnable(GL10.GlBlend); gl.GlBindTexture(GL10.GlTexture2d, _textureId); gl.GlEnableClientState(GL10.GlVertexArray); gl.GlEnableClientState(GL10.GlTextureCoordArray); _vertices.Position(0); gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices); _vertices.Position(2); gl.GlTexCoordPointer(2, GL10.GlFloat, _vertexSize, _vertices); gl.GlDrawArrays(GL10.GlTriangles, 0, 3); //gl.GlDisableClientState(GL10.GlVertexArray); //gl.GlDisableClientState(GL10.GlTextureCoordArray); }
public void OnDrawFrame(IGL10 gl) { // 清除屏幕缓存和深度缓存 gl.GlClear(GL10.GlColorBufferBit | GL10.GlDepthBufferBit); // 启用顶点坐标数据 gl.GlEnableClientState(GL10.GlVertexArray); // 启用贴图坐标数组数据 gl.GlEnableClientState(GL10.GlTextureCoordArray); // ① // 设置当前矩阵模式为模型视图。 gl.GlMatrixMode(GL10.GlModelview); gl.GlLoadIdentity(); // 把绘图中心移入屏幕2个单位 gl.GlTranslatef(0f, 0.0f, -2.0f); // 旋转图形 gl.GlRotatef(ma.angleY, 0, 1, 0); gl.GlRotatef(ma.angleX, 1, 0, 0); // 设置顶点的位置数据 gl.GlVertexPointer(3, GL10.GlFloat, 0, cubeVerticesBuffer); // 设置贴图的坐标数据 gl.GlTexCoordPointer(2, GL10.GlFloat, 0, cubeTexturesBuffer); // ② // 执行纹理贴图 gl.GlBindTexture(GL10.GlTexture2d, texture); // ③ // 按cubeFacetsBuffer指定的面绘制三角形 gl.GlDrawElements(GL10.GlTriangles, cubeFacetsBuffer.Remaining(), GL10.GlUnsignedByte, cubeFacetsBuffer); // 绘制结束 gl.GlFinish(); // 禁用顶点、纹理坐标数组 gl.GlDisableClientState(GL10.GlVertexArray); gl.GlDisableClientState(GL10.GlTextureCoordArray); // 递增角度值以便每次以不同角度绘制 }
public override void Present(float delta) { IGL10 gl = _glGraphics.GL10; gl.GlViewport(0, 0, _glGraphics.Width, _glGraphics.Height - 200); gl.GlClear(GL10.GlColorBufferBit); gl.GlMatrixMode(GL10.GlProjection); gl.GlLoadIdentity(); gl.GlOrthof(0, 540, 0, 960, 1, -1); gl.GlColor4f(1, 0, 0, 1); gl.GlEnableClientState(GL10.GlVertexArray); _vertices.Position(0); gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices); gl.GlDrawArrays(GL10.GlTriangles, 0, 3); }
public void Draw(IGL10 gl) { gl.GlFrontFace(IGL10Constants.GL_CW); gl.GlVertexPointer(3, IGL10Constants.GL_FLOAT, 0, mVertexBuffer); gl.GlColorPointer(4, IGL10Constants.GL_FLOAT, 0, mColorBuffer); gl.GlEnableClientState(IGL10Constants.GL_VERTEX_ARRAY); gl.GlEnableClientState(IGL10Constants.GL_COLOR_ARRAY); // draw all 36 triangles gl.GlDrawElements(IGL10Constants.GL_TRIANGLES, 36, IGL10Constants.GL_UNSIGNED_BYTE, mIndexBuffer); gl.GlDisableClientState(IGL10Constants.GL_VERTEX_ARRAY); gl.GlDisableClientState(IGL10Constants.GL_COLOR_ARRAY); }
public void OnDrawFrame(IGL10 gl) { // Our vertices. float[] vertices = { -1.5f, 1.5f, 0.0f, // 0, Top Left -1.5f, -1.5f, 0.0f, // 1, Bottom Left 1.5f, 1.5f, 0.0f, // 3, Top Right 1.5f, -1.5f, 0.0f, // 2, Bottom Right }; // a float is 4 bytes, therefore we multiply the number if // vertices with 4. ByteBuffer vbb = ByteBuffer.AllocateDirect(vertices.Length * 4); vbb.Order(ByteOrder.NativeOrder()); FloatBuffer vertexBuffer = vbb.AsFloatBuffer(); vertexBuffer.Put(vertices); vertexBuffer.Position(0); // The order we like to connect them. byte[] colors = { (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255 }; // a float is 4 bytes, therefore we multiply the number if // vertices with 4. ByteBuffer cbb = ByteBuffer.AllocateDirect(colors.Length * 4); cbb.Order(ByteOrder.NativeOrder()); cbb.Put(colors); cbb.Position(0); gl.GlVertexPointer(3, GL10.GlFloat, 0, vertexBuffer); gl.GlEnableClientState(GL10.GlVertexArray); gl.GlColorPointer(4, GL10.GlUnsignedByte, 0, cbb); gl.GlEnableClientState(GL10.GlColorArray); gl.GlDrawArrays(GL10.GlTriangleStrip, 0, 4); }
public override void Present(float deltaTime) { IGL10 gl = _glGraphics.GL10; gl.GlViewport(0, 0, _glGraphics.Width, _glGraphics.Height); gl.GlClear(GL10.GlColorBufferBit); gl.GlMatrixMode(GL10.GlProjection); gl.GlLoadIdentity(); gl.GlOrthof(0, 540, 0, 960, 1, -1); gl.GlEnable(GL10.GlTexture2d); _texture.BindTexture(); gl.GlEnableClientState(GL10.GlVertexArray); gl.GlEnableClientState(GL10.GlTextureCoordArray); _vertices.Position(0); gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices); _vertices.Position(2); gl.GlTexCoordPointer(2, GL10.GlFloat, _vertexSize, _vertices); gl.GlDrawElements(GL10.GlTriangles, 6, GL10.GlUnsignedShort, _indices); }
public void OnDrawFrame (IGL10 gl) { // Our vertices. float[] vertices = { -1.5f, 1.5f, 0.0f, // 0, Top Left -1.5f, -1.5f, 0.0f, // 1, Bottom Left 1.5f, 1.5f, 0.0f, // 3, Top Right 1.5f, -1.5f, 0.0f, // 2, Bottom Right }; // a float is 4 bytes, therefore we multiply the number if // vertices with 4. ByteBuffer vbb = ByteBuffer.AllocateDirect(vertices.Length * 4); vbb.Order(ByteOrder.NativeOrder()); FloatBuffer vertexBuffer = vbb.AsFloatBuffer(); vertexBuffer.Put(vertices); vertexBuffer.Position(0); // The order we like to connect them. byte[] colors = { (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255, (byte)0.0, (byte)255 }; // a float is 4 bytes, therefore we multiply the number if // vertices with 4. ByteBuffer cbb = ByteBuffer.AllocateDirect(colors.Length * 4); cbb.Order(ByteOrder.NativeOrder()); cbb.Put (colors); cbb.Position (0); gl.GlVertexPointer (3, GL10.GlFloat, 0, vertexBuffer); gl.GlEnableClientState (GL10.GlVertexArray); gl.GlColorPointer(4, GL10.GlUnsignedByte, 0, cbb); gl.GlEnableClientState (GL10.GlColorArray); gl.GlDrawArrays (GL10.GlTriangleStrip, 0, 4); }
public void Bind() { IGL10 gl = _glGraphics.GL10; gl.GlEnableClientState(GL10.GlVertexArray); _vertices.Position(0); gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices); if (_hasColor) { gl.GlEnableClientState(GL10.GlColorArray); _vertices.Position(2); gl.GlColorPointer(4, GL10.GlFloat, _vertexSize, _vertices); } if (_hasTexCoords) { gl.GlEnableClientState(GL10.GlTextureCoordArray); _vertices.Position(_hasColor?6:2); gl.GlTexCoordPointer(2, GL10.GlFloat, _vertexSize, _vertices); } }
public void OnDrawFrame(IGL10 gl) { // First allocate texture if there is not one yet. if (DRAW_TEXTURE && mTextureIds == null) { // Generate texture. mTextureIds = new int[2]; gl.GlGenTextures(2, mTextureIds, 0); foreach (int textureId in mTextureIds) { // Set texture attributes. gl.GlBindTexture(GL10.GlTexture2d, textureId); gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureMinFilter, GL10.GlNearest); gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureMagFilter, GL10.GlNearest); gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureWrapS, GL10.GlClampToEdge); gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureWrapT, GL10.GlClampToEdge); } } if (DRAW_TEXTURE && mTexturePage.TexturesChanged) { gl.GlBindTexture(GL10.GlTexture2d, mTextureIds[0]); Bitmap texture = mTexturePage.GetTexture(mTextureRectFront, CurlPage.SIDE_FRONT); GLUtils.TexImage2D(GL10.GlTexture2d, 0, texture, 0); texture.Recycle(); mTextureBack = mTexturePage.HasBackTexture; if (mTextureBack) { gl.GlBindTexture(GL10.GlTexture2d, mTextureIds[1]); texture = mTexturePage.GetTexture(mTextureRectBack, CurlPage.SIDE_BACK); GLUtils.TexImage2D(GL10.GlTexture2d, 0, texture, 0); texture.Recycle(); } else { mTextureRectBack.Set(mTextureRectFront); } mTexturePage.Recycle(); Reset(); } // Some 'global' settings. gl.GlEnableClientState(GL10.GlVertexArray); // TODO: Drop shadow drawing is done temporarily here to hide some // problems with its calculation. if (DRAW_SHADOW) { gl.GlDisable(GL10.GlTexture2d); gl.GlEnable(GL10.GlBlend); gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlEnableClientState(GL10.GlColorArray); gl.GlColorPointer(4, GL10.GlFloat, 0, mBufShadowColors); gl.GlVertexPointer(3, GL10.GlFloat, 0, mBufShadowVertices); gl.GlDrawArrays(GL10.GlTriangleStrip, 0, mDropShadowCount); gl.GlDisableClientState(GL10.GlColorArray); gl.GlDisable(GL10.GlBlend); } if (DRAW_TEXTURE) { gl.GlEnableClientState(GL10.GlTextureCoordArray); gl.GlTexCoordPointer(2, GL10.GlFloat, 0, mBufTexCoords); } gl.GlVertexPointer(3, GL10.GlFloat, 0, mBufVertices); // Enable color array. gl.GlEnableClientState(GL10.GlColorArray); gl.GlColorPointer(4, GL10.GlFloat, 0, mBufColors); // Draw front facing blank vertices. gl.GlDisable(GL10.GlTexture2d); gl.GlDrawArrays(GL10.GlTriangleStrip, 0, mVerticesCountFront); // Draw front facing texture. if (DRAW_TEXTURE) { gl.GlEnable(GL10.GlBlend); gl.GlEnable(GL10.GlTexture2d); if (!mFlipTexture || !mTextureBack) { gl.GlBindTexture(GL10.GlTexture2d, mTextureIds[0]); } else { gl.GlBindTexture(GL10.GlTexture2d, mTextureIds[1]); } gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlDrawArrays(GL10.GlTriangleStrip, 0, mVerticesCountFront); gl.GlDisable(GL10.GlBlend); gl.GlDisable(GL10.GlTexture2d); } int backStartIdx = Math.Max(0, mVerticesCountFront - 2); int backCount = mVerticesCountFront + mVerticesCountBack - backStartIdx; // Draw back facing blank vertices. gl.GlDrawArrays(GL10.GlTriangleStrip, backStartIdx, backCount); // Draw back facing texture. if (DRAW_TEXTURE) { gl.GlEnable(GL10.GlBlend); gl.GlEnable(GL10.GlTexture2d); if (mFlipTexture || !mTextureBack) { gl.GlBindTexture(GL10.GlTexture2d, mTextureIds[0]); } else { gl.GlBindTexture(GL10.GlTexture2d, mTextureIds[1]); } gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlDrawArrays(GL10.GlTriangleStrip, backStartIdx, backCount); gl.GlDisable(GL10.GlBlend); gl.GlDisable(GL10.GlTexture2d); } // Disable textures and color array. gl.GlDisableClientState(GL10.GlTextureCoordArray); gl.GlDisableClientState(GL10.GlColorArray); if (DRAW_POLYGON_OUTLINES) { gl.GlEnable(GL10.GlBlend); gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlLineWidth(1.0f); gl.GlColor4f(0.5f, 0.5f, 1.0f, 1.0f); gl.GlVertexPointer(3, GL10.GlFloat, 0, mBufVertices); gl.GlDrawArrays(GL10.GlLineStrip, 0, mVerticesCountFront); gl.GlDisable(GL10.GlBlend); } if (DRAW_CURL_POSITION) { gl.GlEnable(GL10.GlBlend); gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlLineWidth(1.0f); gl.GlColor4f(1.0f, 0.5f, 0.5f, 1.0f); gl.GlVertexPointer(2, GL10.GlFloat, 0, mBufCurlPositionLines); gl.GlDrawArrays(GL10.GlLines, 0, mCurlPositionLinesCount * 2); gl.GlDisable(GL10.GlBlend); } if (DRAW_SHADOW) { gl.GlEnable(GL10.GlBlend); gl.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); gl.GlEnableClientState(GL10.GlColorArray); gl.GlColorPointer(4, GL10.GlFloat, 0, mBufShadowColors); gl.GlVertexPointer(3, GL10.GlFloat, 0, mBufShadowVertices); gl.GlDrawArrays(GL10.GlTriangleStrip, mDropShadowCount, mSelfShadowCount); gl.GlDisableClientState(GL10.GlColorArray); gl.GlDisable(GL10.GlBlend); } gl.GlDisableClientState(GL10.GlVertexArray); }
/// <summary> /// Raises the draw frame event. /// </summary> /// <param name="gl">Gl.</param> public void OnDrawFrame(IGL10 gl) { lock (_triangles) { // Replace the current matrix with the identity matrix gl.GlMatrixMode(GL10.GlProjection); gl.GlLoadIdentity(); // OpenGL docs gl.GlOrthof(_left, _right, _bottom, _top, -1, 1); SimpleColor color = SimpleColor.FromKnownColor(KnownColor.White); gl.GlClearColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); gl.GlClear(GL10.GlColorBufferBit); for (int idx = 0; idx < _triangles.Count; idx++) { gl.GlVertexPointer(3, GL10.GlFloat, 0, _triangles[idx].Vertices); gl.GlEnableClientState(GL10.GlVertexArray); gl.GlColorPointer(4, GL10.GlUnsignedByte, 0, _triangles[idx].Colors); gl.GlEnableClientState(GL10.GlColorArray); gl.GlDrawArrays(GL10.GlTriangleStrip, 0, _triangles[idx].Count); } for (int idx = 0; idx < _lines.Count; idx++) { gl.GlVertexPointer(3, GL10.GlFloat, 0, _lines[idx].Vertices); gl.GlEnableClientState(GL10.GlVertexArray); color = new SimpleColor() { Value = _lines[idx].Color }; gl.GlColor4f(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); gl.GlLineWidth(_lines[idx].Width); gl.GlDrawArrays(GL10.GlLineStrip, 0, _lines[idx].Count); } } }
public void Draw (IGL10 gl) { gl.GlFrontFace (GL10.GlCw); gl.GlVertexPointer (3, GL10.GlFixed, 0, mVertexBuffer); gl.GlColorPointer (4, GL10.GlFixed, 0, mColorBuffer); gl.GlDrawElements (GL10.GlTriangles, 36, GL10.GlUnsignedByte, mIndexBuffer); }