Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        public Material CreateTextureMaterial(SizeStream texture)
        {
            byte[] textureData = new byte[texture.Size];
            int iltexid = Il.ilGenImage();
            int gltexid = 0;
            int read = 1, readTotal = 0;

            Il.ilBindImage(iltexid);

            while (read > 0) {
                read = texture.InputStream.Read(textureData, readTotal, texture.Size);
                readTotal += read;
            }

            if ((textureData[0] == 0x89) && (textureData[1] == 0x50)) {
                Il.ilLoadL(Il.IL_PNG, textureData, texture.Size);
            } else if ((textureData[0] == 0xFF) && (textureData[1] == 0xD8)) {
                Il.ilLoadL(Il.IL_JPG, textureData, texture.Size);
            } else if ((textureData[0] == 'B') && (textureData[1] == 'M')) {
                Il.ilLoadL(Il.IL_BMP, textureData, texture.Size);
            }

            Gl.glGenTextures(1, out gltexid);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, gltexid);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
            Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Il.ilGetInteger(Il.IL_IMAGE_BPP),
                            Il.ilGetInteger(Il.IL_IMAGE_WIDTH), Il.ilGetInteger(Il.IL_IMAGE_HEIGHT),
                            0, Il.ilGetInteger(Il.IL_IMAGE_FORMAT), Gl.GL_UNSIGNED_BYTE, Il.ilGetData());

            Material material = new Material(Material.TEXTURE0, gltexid);

            Il.ilDeleteImage(iltexid);

            return material;
        }