Exemplo n.º 1
0
        public static int BuildRectangle(float X, float Y, float Width, float Height)
        {
            Vertex[] d = new Vertex[4];
            for (int i = 0; i < d.Length; ++i) {
                d [i] = new Vertex();
                d [i].Color = new Vector4(1, 1, 1, 1);
            }
            d [0].Position.X = X;
            d [0].Position.Y = Y;
            d [0].TexCoord.X = 0;
            d [0].TexCoord.Y = 0;

            d [1].Position.X = X;
            d [1].Position.Y = Y + Height;
            d [1].TexCoord.X = 0;
            d [1].TexCoord.Y = 1;

            d [2].Position.X = X + Width;
            d [2].Position.Y = Y + Height;
            d [2].TexCoord.X = 1;
            d [2].TexCoord.Y = 1;

            d [3].Position.X = X + Width;
            d [3].Position.Y = Y;
            d [3].TexCoord.X = 1;
            d [3].TexCoord.Y = 0;

            int tr = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, tr);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(d.Length * Vertex.Size), d, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            return tr;
        }
Exemplo n.º 2
0
 public Model(Vertex[] Verts, Bitmap Texture)
 {
     _buffs = new uint[NUM_BUFFS];
     _numverts = Verts.Length;
     GL.GenBuffers(NUM_BUFFS, _buffs);
     //Vertex Data
     GL.BindBuffer(BufferTarget.ArrayBuffer, _buffs [VERT_INDEX]);
     GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Verts.Length * Vertex.Size), Verts, BufferUsageHint.StaticDraw);
     GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
     //Texture data
     _texid = GLUtil.CreateTexture(Texture);
 }
Exemplo n.º 3
0
 void SetPos(ref Vertex V, float X, float Y, float Z)
 {
     V.Position.X = X;
     V.Position.Y = Y;
     V.Position.Z = Z;
 }
Exemplo n.º 4
0
 void BuildWater(HeightMap In, List<Vertex> V, List<ushort> I)
 {
     int basex = _cx * CHUNK_SIZE;
     int basey = _cy * CHUNK_SIZE;
     int itr = CHUNK_SIZE / _lod;
     for (int x = 0; x < CHUNK_SIZE + itr; x += itr) {
         int xp = basex + x;
         for (int y = 0; y < CHUNK_SIZE + itr; y += itr) {
             int yp = basey + y;
             Vertex tmp = new Vertex();
             SetPos(ref tmp, xp, 0, yp);
             tmp.TexCoord.X = x / (float)CHUNK_SIZE;
             tmp.TexCoord.Y = y / (float)CHUNK_SIZE;
             tmp.Color = new Vector4(1, 1, 1, 1);
             V.Add(tmp);
         }
     }
     for (int x = 0; x < _lod; ++x) {
         for (int y = 0; y < _lod; ++y) {
             int vi = x + y * (_lod + 1);
             I.Add((ushort)(vi + _lod + 1));
             I.Add((ushort)(vi));
             I.Add((ushort)(vi + 1));
             I.Add((ushort)(vi + _lod + 1));
             I.Add((ushort)(vi + 1));
             I.Add((ushort)(vi + _lod + 2));
         }
     }
 }
Exemplo n.º 5
0
 void ReadFace(string[] Line, ref List<Vector3> Pos, ref List<Vector3> Norm, ref List<Vector2> Tex, ref List<Vertex> Out)
 {
     for (int i = 0; i < Line.Length - 1; ++i) {
         string[] v = Line [i + 1].Split(FSLASH);
         Vertex tmp = new Vertex();
         tmp.Position = Pos [int.Parse(v [0]) - 1];
         tmp.Color.X = 1;//(float)r.NextDouble();
         tmp.Color.Y = 1;//(float)r.NextDouble();
         tmp.Color.Z = 1;//(float)r.NextDouble();
         tmp.TexCoord = Tex [int.Parse(v [1]) - 1];
         tmp.TexCoord.Y = 1 - tmp.TexCoord.Y; //fix sillyness
         tmp.Normal = Norm [int.Parse(v [2]) - 1];
         Out.Add(tmp);
     }
 }