예제 #1
0
        /**
         * Load texture image from file and create GL texture object.
         * */
        public void Load(string filename)
        {
            this.filename = filename;
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentException(filename);
            }

            textureId = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, textureId);

            string     path     = AssetPath.GetPathToAsset(filename);
            Image      image    = Image.FromFile(path);
            Bitmap     bmp      = new Bitmap(image);
            BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            bmp.UnlockBits(bmp_data);

            Console.WriteLine("Texture " + filename + " loaded.");
        }
예제 #2
0
        /**
         * Read an OBJ file an create a mesh from the content.
         * */
        public void Read(string filename, ITriangleMesh mesh)
        {
            this.mesh = mesh;
            mesh.Clear();

            // Read input
            string objSource = System.IO.File.ReadAllText(AssetPath.GetPathToAsset(filename));

            string[] lines = objSource.Split('\n');
            foreach (String line in lines)
            {
                string[] tokens = line.Trim().Split(' ', '\t');
                if (tokens.Length > 0)
                {
                    if (tokens [0].CompareTo("v") == 0)
                    {
                        ParseVertex(tokens);
                    }
                    else if (tokens [0].CompareTo("f") == 0)
                    {
                        ParseFacet(tokens);
                    }
                    else if (tokens [0].CompareTo("vt") == 0)
                    {
                        ParseTextureCoordinate(tokens);
                    }
                }
            }

            mesh.ComputeTriangleNormals();
            Console.WriteLine("Read mesh from file " + filename + " with " + mesh.GetNumberOfTriangles() + " triangles and " + mesh.GetNumberOfVertices() + " vertices.");
        }
예제 #3
0
 /**
  * Read source from text file.
  * */
 private string ReadShaderSource(string filename)
 {
     return(System.IO.File.ReadAllText(AssetPath.GetPathToAsset(filename)));
 }