Ejemplo n.º 1
0
        /// <summary>
        /// Prepares the system, registering built-in material textures.
        /// </summary>
        public static void Init()
        {
            Textures           = new Dictionary <ushort, MaterialSideData>();
            TexturesDefault[0] = null;
            TexturesDefault[1] = new MaterialSideData(Texture.GetTexture("blocks/solid/stone"));
            TexturesDefault[2] = new MaterialSideData(Texture.GetTexture("blocks/solid/dirt"));
            MaterialSideData grass = new MaterialSideData(Texture.GetTexture("blocks/solid/grass_side"));

            grass.Textures[(int)Sides.TOP]    = Texture.GetTexture("blocks/solid/grass");
            grass.Textures[(int)Sides.BOTTOM] = Texture.GetTexture("blocks/solid/dirt");
            TexturesDefault[3] = grass;
            TexturesDefault[4] = new MaterialSideData(Texture.GetTexture("blocks/solid/wood"));
            TexturesDefault[5] = new MaterialSideData(Texture.GetTexture("blocks/solid/redstone"));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// (Re-)Generate the Vertex Buffer Object for this chunk (IE, update its rendered state on the GPU.)
 /// </summary>
 public void UpdateVBO()
 {
     for (int i = 0; i < VBOs.Count; i++)
     {
         VBOs[i].Destroy();
     }
     VBOs.Clear();
     for (int x = 0; x < 30; x++)
     {
         for (int y = 0; y < 30; y++)
         {
             for (int z = 0; z < 30; z++)
             {
                 MaterialSideData tex = MaterialTexture.GetTexture((Material)Blocks[x, y, z].Type);
                 if (tex != null)
                 {
                     // TODO: Simplify. Can this be a loop?
                     if ((z != 29 && !((Material)Blocks[x, y, z + 1].Type).OccupiesWholeBlock()) ||
                         (z == 29 && !((Material)ClientMain.GetChunk(new Location(X, Y, Z + 1)).
                                       Blocks[x, y, 0].Type).OccupiesWholeBlock()))
                     {
                         GetVBO(tex.Textures[(int)Sides.TOP]).AddSide(X * 30 + x, Y * 30 + y, Z * 30 + z, new OpenTK.Vector3(0, 0, 1));
                     }
                     if ((z != 0 && !((Material)Blocks[x, y, z - 1].Type).OccupiesWholeBlock()) ||
                         (z == 0 && !((Material)ClientMain.GetChunk(new Location(X, Y, Z - 1)).
                                      Blocks[x, y, 29].Type).OccupiesWholeBlock()))
                     {
                         GetVBO(tex.Textures[(int)Sides.BOTTOM]).AddSide(X * 30 + x, Y * 30 + y, Z * 30 + z, new OpenTK.Vector3(0, 0, -1));
                     }
                     if ((x != 29 && !((Material)Blocks[x + 1, y, z].Type).OccupiesWholeBlock()) ||
                         (x == 29 && !((Material)ClientMain.GetChunk(new Location(X + 1, Y, Z)).
                                       Blocks[0, y, z].Type).OccupiesWholeBlock()))
                     {
                         GetVBO(tex.Textures[(int)Sides.XP]).AddSide(X * 30 + x, Y * 30 + y, Z * 30 + z, new OpenTK.Vector3(1, 0, 0));
                     }
                     if ((x != 0 && !((Material)Blocks[x - 1, y, z].Type).OccupiesWholeBlock()) ||
                         (x == 0 && !((Material)ClientMain.GetChunk(new Location(X - 1, Y, Z)).
                                      Blocks[29, y, z].Type).OccupiesWholeBlock()))
                     {
                         GetVBO(tex.Textures[(int)Sides.XM]).AddSide(X * 30 + x, Y * 30 + y, Z * 30 + z, new OpenTK.Vector3(-1, 0, 0));
                     }
                     if ((y != 29 && !((Material)Blocks[x, y + 1, z].Type).OccupiesWholeBlock()) ||
                         (y == 29 && !((Material)ClientMain.GetChunk(new Location(X, Y + 1, Z)).
                                       Blocks[x, 0, z].Type).OccupiesWholeBlock()))
                     {
                         GetVBO(tex.Textures[(int)Sides.YP]).AddSide(X * 30 + x, Y * 30 + y, Z * 30 + z, new OpenTK.Vector3(0, 1, 0));
                     }
                     if ((y != 0 && !((Material)Blocks[x, y - 1, z].Type).OccupiesWholeBlock()) ||
                         (y == 0 && !((Material)ClientMain.GetChunk(new Location(X, Y - 1, Z)).
                                      Blocks[x, 29, z].Type).OccupiesWholeBlock()))
                     {
                         GetVBO(tex.Textures[(int)Sides.YM]).AddSide(X * 30 + x, Y * 30 + y, Z * 30 + z, new OpenTK.Vector3(0, -1, 0));
                     }
                 }
             }
         }
     }
     for (int i = 0; i < VBOs.Count; i++)
     {
         VBOs[i].Build();
     }
 }