Example #1
0
        public void Draw(IRender render)
        {
            render.Apply();

            if (demo.EnableVertexBuffer)
            {
                if (meshVertexBuffer != -1)
                {
                    if (meshIndexBuffer != -1)
                    {
                        GL.EnableClientState(ArrayCap.VertexArray);
                        GL.EnableClientState(ArrayCap.NormalArray);
                        GL.EnableClientState(ArrayCap.TextureCoordArray);

                        GL.BindBuffer(BufferTarget.ArrayBuffer, meshVertexBuffer);
                        GL.BindBuffer(BufferTarget.ElementArrayBuffer, meshIndexBuffer);

                        GL.VertexPointer(3, VertexPointerType.Float, VertexPositionNormalTexture.SizeInBytes, IntPtr.Zero);
                        GL.NormalPointer(NormalPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)Vector3.SizeInBytes);
                        GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)(Vector3.SizeInBytes + Vector3.SizeInBytes));

                        GL.DrawElements(PrimitiveType.Triangles, indexCount, meshIndicesType, 0);

                        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
                        GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
                        GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
                        GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
                        GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);

                        GL.DisableClientState(ArrayCap.VertexArray);
                        GL.DisableClientState(ArrayCap.NormalArray);
                        GL.DisableClientState(ArrayCap.TextureCoordArray);
                    }
                    else
                    {
                        GL.EnableClientState(ArrayCap.VertexArray);
                        GL.EnableClientState(ArrayCap.NormalArray);
                        GL.EnableClientState(ArrayCap.TextureCoordArray);

                        GL.BindBuffer(BufferTarget.ArrayBuffer, meshVertexBuffer);

                        GL.VertexPointer(3, VertexPointerType.Float, VertexPositionNormalTexture.SizeInBytes, IntPtr.Zero);
                        GL.NormalPointer(NormalPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)Vector3.SizeInBytes);
                        GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPositionNormalTexture.SizeInBytes, (IntPtr)(Vector3.SizeInBytes + Vector3.SizeInBytes));

                        GL.DrawArrays(PrimitiveType.Triangles, 0, vertexCount);

                        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
                        GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
                        GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
                        GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);

                        GL.DisableClientState(ArrayCap.VertexArray);
                        GL.DisableClientState(ArrayCap.NormalArray);
                        GL.DisableClientState(ArrayCap.TextureCoordArray);
                    }
                }
            }
            else
            {
                VertexPositionNormalTexture v1, v2, v3;

                if (meshIndices16Bit != null)
                {
                    GL.Begin(PrimitiveType.Triangles);

                    for (int i = 0; i < indexCount; i += 3)
                    {
                        v1 = meshVertices[meshIndices16Bit[i]];
                        v2 = meshVertices[meshIndices16Bit[i + 1]];
                        v3 = meshVertices[meshIndices16Bit[i + 2]];

                        GL.TexCoord2(v1.TextureCoordinate);
                        GL.Normal3(v1.Normal);
                        GL.Vertex3(v1.Position);

                        GL.TexCoord2(v2.TextureCoordinate);
                        GL.Normal3(v2.Normal);
                        GL.Vertex3(v2.Position);

                        GL.TexCoord2(v3.TextureCoordinate);
                        GL.Normal3(v3.Normal);
                        GL.Vertex3(v3.Position);
                    }

                    GL.End();
                }
                else
                if (meshIndices32Bit != null)
                {
                    GL.Begin(PrimitiveType.Triangles);

                    for (int i = 0; i < indexCount; i += 3)
                    {
                        v1 = meshVertices[meshIndices32Bit[i]];
                        v2 = meshVertices[meshIndices32Bit[i + 1]];
                        v3 = meshVertices[meshIndices32Bit[i + 2]];

                        GL.TexCoord2(v1.TextureCoordinate);
                        GL.Normal3(v1.Normal);
                        GL.Vertex3(v1.Position);

                        GL.TexCoord2(v2.TextureCoordinate);
                        GL.Normal3(v2.Normal);
                        GL.Vertex3(v2.Position);

                        GL.TexCoord2(v3.TextureCoordinate);
                        GL.Normal3(v3.Normal);
                        GL.Vertex3(v3.Position);
                    }

                    GL.End();
                }
                else
                {
                    GL.Begin(PrimitiveType.Triangles);

                    for (int i = 0; i < vertexCount; i += 3)
                    {
                        v1 = meshVertices[i];
                        v2 = meshVertices[i + 1];
                        v3 = meshVertices[i + 2];

                        GL.TexCoord2(v1.TextureCoordinate);
                        GL.Normal3(v1.Normal);
                        GL.Vertex3(v1.Position);

                        GL.TexCoord2(v2.TextureCoordinate);
                        GL.Normal3(v2.Normal);
                        GL.Vertex3(v2.Position);

                        GL.TexCoord2(v3.TextureCoordinate);
                        GL.Normal3(v3.Normal);
                        GL.Vertex3(v3.Position);
                    }

                    GL.End();
                }
            }
        }