예제 #1
0
파일: Main.cs 프로젝트: INightmare/iron
        public static void Main(string[] args)
        {
            IronClient.Renderer.Renderer renderer = new IronClient.Renderer.OpenGL.OGLRenderer();

            if (!renderer.CreateWindow(800, 600, false))
                return;

            StaticMesh mesh = new StaticMesh();
            mesh.vertices = new Vertex[] { new Vertex(0.0f, 1.0f, 0.0f), new Vertex(-1.0f, -1.0f, 0.0f),
                new Vertex(1.0f, -1.0f, 0.0f)};
            mesh.texCoords0 = new TexCoord[] { new TexCoord(0.5f, 0.0f), new TexCoord(0.0f, 1.0f),
                new TexCoord(1.0f, 1.0f) };
            mesh.MeshType = MeshType.TRIANGLES;

            FileSystem fs = FileSystem.GetInstance();
            fs.AddZipArchive("test.zip");

            Stream stream = new FileStream("testtex.png", FileMode.Open);
            SizeStream ss = new SizeStream(stream, (int)stream.Length);
            mesh.Material = MaterialManager.getInstance().CreateTextureMaterial(fs.Get("testtex.png"));

            while (renderer.IsOpen()) {

                renderer.Clear();
                renderer.DrawStaticMesh(mesh);
                renderer.Render();
            }
        }
예제 #2
0
        public void DrawStaticMesh(StaticMesh mesh)
        {
            //uint buffer0, buffer1;

            if (mesh.Material.Type == Material.TEXTURE0) {
                Gl.glEnable(Gl.GL_TEXTURE_2D);
                Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
                Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);

                Gl.glBindTexture(Gl.GL_TEXTURE_2D, mesh.Material.Texture0);
                Gl.glVertexPointer(mesh.vertices.Length, Gl.GL_FLOAT, 0, mesh.vertices);
                Gl.glTexCoordPointer(mesh.texCoords0.Length, Gl.GL_FLOAT, 0, mesh.texCoords0);

                if (mesh.MeshType == MeshType.TRIANGLES)
                    Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, mesh.vertices.Length);
                else if (mesh.MeshType == MeshType.QUADS)
                    Gl.glDrawArrays(Gl.GL_QUADS, 0, mesh.vertices.Length);
                else Gl.glDrawArrays(Gl.GL_POLYGON, 0, mesh.vertices.Length);

                Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
                Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
            } else throw new Exception("Unsupported material type");
        }
예제 #3
0
        /* To be used for VBO binding */
        public void RegisterPolygon(StaticMesh mesh)
        {
            /*
            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);

            Gl.glGenBuffers(1, out mesh.VBuffer);
            Gl.glGenBuffers(1, out mesh.texCoords0);

            Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY);*/
        }