Inheritance: IDisposable
 public static Spritesheet Load(Bitmap TextureBitmap, int width, int height, TextureFilteringMode mode)
 {
     var ret = new Spritesheet();
     ret.Texture = Texture2D.Load(TextureBitmap, mode);
     ret.TileWidth = width;
     ret.TileHeight = height;
     ret.Rows = TextureBitmap.Width / width;
     ret.Columns = TextureBitmap.Height / height;
     ret.RowSize = TextureBitmap.Width;
     ret.ColumnSize = TextureBitmap.Height;
     return ret;
 }
        // TODO: Refactor to utilize FBO thing
        public void RefreshChunks(Spritesheet[] globalSheets, Spritesheet[] localSheets, int xPos, int yPos, double scale)
        {
            if (drawTiles == null || drawTiles.Count == 0)
            {
                drawTiles = new List<VisualMapTile>();
                int tilesx = Math.Max(layoutWidth / 16, 1);
                int tilesy = Math.Max(layoutHeight / 16, 1);
                tilesx += layoutWidth % tilesx;
                tilesy += layoutWidth % tilesy;

                int tileWidth = layoutWidth / tilesx;
                int tileHeight = layoutHeight / tilesy;
                int xtiles = layoutWidth / tileWidth;
                int ytiles = layoutHeight / tileHeight;
                for (int y = 0; y < ytiles; y++)
                {
                    for (int x = 0; x < xtiles; x++)
                    {
                        var tile = new VisualMapTile();
                        tile.Width = tileWidth;
                        tile.Height = tileHeight;
                        tile.buffer = new FrameBuffer(tileWidth * 16, tileHeight * 16);
                        tile.xpos = x * tileWidth;
                        tile.ypos = y * tileHeight;
                        drawTiles.Add(tile);
                    }
                }

                int xremain = layoutWidth - xtiles * tileWidth;
                int yremain = layoutHeight - ytiles * tileHeight;
                if (xremain > 0)
                    for (int y = 0; y < ytiles; y++)
                    {
                        var tile = new VisualMapTile();
                        tile.Width = xremain;
                        tile.Height = tileHeight;
                        tile.buffer = new FrameBuffer(tile.Width * 16, tile.Height * 16);
                        tile.xpos = xtiles * tileWidth;
                        tile.ypos = y * tileHeight;
                        drawTiles.Add(tile);
                    }

                if (yremain > 0)
                    for (int x = 0; x < xtiles; x++)
                    {
                        var tile = new VisualMapTile();
                        tile.Width = tileWidth;
                        tile.Height = yremain;
                        tile.buffer = new FrameBuffer(tile.Width * 16, tile.Height * 16);
                        tile.xpos = x * tileWidth;
                        tile.ypos = ytiles * tileHeight;
                        drawTiles.Add(tile);
                    }

                if ((xremain > 0) && (yremain > 0))
                {
                    var tile = new VisualMapTile();
                    tile.Width = xremain;
                    tile.Height = yremain;
                    tile.buffer = new FrameBuffer(tile.Width * 16, tile.Height * 16);
                    tile.xpos = xtiles * tileWidth;
                    tile.ypos = ytiles * tileHeight;
                    drawTiles.Add(tile);
                }
            }

            foreach (var v in drawTiles)
            {
                if (v.Redraw)
                {
                    FrameBuffer.Active = v.buffer;
                    GL.PushMatrix();
                    {
                        int xoff = v.xpos * 16;
                        int yoff = v.ypos * 16;
                        for (int i = v.ypos; i < v.ypos + v.Height; i++)
                        {
                            for (int j = v.xpos; j < v.xpos + v.Width; j++)
                            {
                                short block = layout[i * layoutWidth + j];
                                short blockIndex = (short)(block & 0x3FF);
                                byte movementPerm = (byte)((block & 0xFC00) >> 10);

                                if (blockIndex < Program.currentGame.MainTSBlocks)
                                {
                                    if (globalTileset != null)
                                        globalTileset.blockSet.blocks[blockIndex].Draw(globalSheets, localSheets, xPos + j * 16 - xoff, yPos + i * 16 - yoff, scale);
                                    else
                                        Surface.DrawRect(xPos - xoff, yPos - yoff, 16, 16, Color.Black);
                                }
                                else
                                {
                                    if (localTileset != null)
                                        localTileset.blockSet.blocks[blockIndex - Program.currentGame.MainTSBlocks].Draw(globalSheets, localSheets, xPos + j * 16 - xoff, yPos + i * 16 - yoff, scale);
                                    else
                                        Surface.DrawRect(xPos - xoff, yPos - yoff, 16, 16, Color.Black);
                                }

                                if (Program.showingPerms)
                                {
                                    Program.glMapEditor.movementPerms.Draw(movementPerm, xPos + j * 16 - xoff, yPos + i * 16 - yoff, scale, (((Program.mainGUI.PermTransPreviewValue() >= 0) ? Program.mainGUI.PermTransPreviewValue() : Config.settings.PermissionTranslucency) * 255) / 100);
                                }
                            }
                        }

                        GL.PopMatrix();
                    }
                    FrameBuffer.Active = null;
                    v.Redraw = false;
                }
            }
        }
        public void DrawBorder(Spritesheet[] globalSheets, Spritesheet[] localSheets, int xPos, int yPos, double scale)
        {
            for (int i = 0; i < borderHeight; i++)
            {
                for (int j = 0; j < borderWidth; j++)
                {
                    short block = border[i * borderWidth + j];
                    short blockIndex = (short)(block & 0x3FF);

                    if (blockIndex < Program.currentGame.MainTSBlocks)
                    {
                        if (globalTileset != null)
                            globalTileset.blockSet.blocks[blockIndex].Draw(globalSheets, localSheets, xPos + j * 16, yPos + i * 16, scale);
                        else
                            Surface.DrawRect(xPos, yPos, 16, 16, Color.Black);
                    }
                    else
                    {
                        if (localTileset != null)
                            localTileset.blockSet.blocks[blockIndex - Program.currentGame.MainTSBlocks].Draw(globalSheets, localSheets, xPos + j * 16, yPos + i * 16, scale);
                        else
                            Surface.DrawRect(xPos, yPos, 16, 16, Color.Black);
                    }
                }
            }

            Surface.SetTexture(null);
        }
        public void Draw(Spritesheet[] globalSheets, Spritesheet[] localSheets, int xPos, int yPos, double scale)
        {
            GL.Disable(EnableCap.Blend);
            foreach (var v in drawTiles)
            {
                Surface.SetColor(Color.White);
                Surface.SetTexture(v.buffer.ColorTexture);
                Surface.DrawRect(v.xpos * 16, v.ypos * 16, v.buffer.Width, v.buffer.Height);
            }

            GL.Enable(EnableCap.Blend);

            /*
            foreach (var v in drawTiles)
            {
                Surface.SetTexture(null);
                Surface.SetColor(Color.Cyan);
                Surface.DrawOutlineRect(v.xpos * 16, v.ypos * 16, v.buffer.Width, v.buffer.Height);
            }
            // */

            Surface.SetTexture(null);
        }
 public void Draw(Spritesheet[] globalSheets, Spritesheet[] localSheets, int xPos, int yPos, double scale)
 {
     if (index < Program.currentGame.MainTSSize)
     {
         if (globalSheets != null && globalSheets[palette] != null)
             globalSheets[palette].Draw(index, xPos, yPos, xFlip, yFlip, scale);
         else
             Surface.DrawRect(xPos, yPos, 8, 8, Color.Black);
     }
     else
     {
         if (localSheets != null && localSheets[palette] != null)
             localSheets[palette].Draw(index - Program.currentGame.MainTSSize, xPos, yPos, xFlip, yFlip, scale);
         else
             Surface.DrawRect(xPos, yPos, 8, 8, Color.Black);
     }
 }
 public void Draw(Spritesheet[] globalSheets, Spritesheet[] localSheets, int xPos, int yPos, double scale)
 {
     for (int i = 0; i < blocks.Length / 8; i++)
         for (int j = 0; j < 8; j++)
             blocks[j + (i * 8)].Draw(globalSheets, localSheets, xPos + j * 16, yPos + i * 16, scale);
 }
 public void Draw(Spritesheet[] globalSheets, Spritesheet[] localSheets, int xPos, int yPos, double scale)
 {
     GL.Disable(EnableCap.Blend);
     for (int i = 0; i < 4; i++)
     {
         tileArray[i].Draw(globalSheets, localSheets, xPos + ((i % 2) * 8), yPos + (((i % 4) / 2) * 8), scale);
     }
     GL.Enable(EnableCap.Blend);
     for (int i = 4; i < tileArray.Length; i++)
     {
         tileArray[i].Draw(globalSheets, localSheets, xPos + ((i % 2) * 8), yPos + (((i % 4) / 2) * 8), scale);
     }
 }