/// <summary>
        /// Loads the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TileSetForm_Load(object sender, EventArgs e)
        {
            GLTileControl.MakeCurrent();
            Display.RenderState.Blending = true;
            Display.BlendingFunction(BlendingFactorSource.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GLTextureControl.MakeCurrent();
            Display.RenderState.Blending = true;
            Display.BlendingFunction(BlendingFactorSource.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);


            Batch = new SpriteBatch();

            CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png"));
            CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat;
            CheckerBoard.VerticalWrap   = TextureWrapFilter.Repeat;

            TileSet.Load(Node);

            TextureNameBox.Text = TileSet.TextureName;

            BMFont = BitmapFont.CreateFromTTF(@"c:\windows\fonts\verdana.ttf", 12, FontStyle.Bold);
        }
 /// <summary>
 /// Timer Tick
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void RenderTimer_Tick(object sender, EventArgs e)
 {
     GLTextureControl.Invalidate();
     GLTileControl.Invalidate();
 }
 /// <summary>
 /// OnResize event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GLTextureControl_Resize(object sender, EventArgs e)
 {
     GLTextureControl.MakeCurrent();
     Display.ViewPort = new Rectangle(Point.Empty, GLTextureControl.Size);
 }
        /// <summary>
        /// Paint event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GLTextureControl_Paint(object sender, PaintEventArgs e)
        {
            GLTextureControl.MakeCurrent();
            Display.ViewPort = new Rectangle(Point.Empty, GLTextureControl.Size);


            // Background color
            Display.ClearBuffers();


            Batch.Begin();


            // Background texture
            Rectangle dst = new Rectangle(Point.Empty, GLTextureControl.Size);

            Batch.Draw(CheckerBoard, dst, dst, Color.White);



            float ZoomFactor = float.Parse((string)ZoomBox.SelectedItem);

            if (TileSet.Texture != null)
            {
                // Draw the tile texture
                Vector4 zoom = new Vector4(
                    TextureOffset.X,
                    TextureOffset.Y,
                    TileSet.Texture.Bounds.Width * ZoomFactor,
                    TileSet.Texture.Bounds.Height * ZoomFactor);

                Vector4 src = new Vector4(0.0f, 0.0f, TileSet.Texture.Size.Width, TileSet.Texture.Size.Height);

                Batch.Draw(TileSet.Texture, zoom, src, Color.White);



                // Draw the selection box with sizing handles
                if (CurrentTile != null)
                {
                    SelectionTool.Zoom    = ZoomFactor;
                    SelectionTool.Offset  = TextureOffset;
                    CurrentTile.Rectangle = SelectionTool.Rectangle;
                    SelectionTool.Draw(Batch);
                }
            }

            // Suround all tiles
            if (SurroundTilesBox.Checked)
            {
                foreach (int id in TileSet.Tiles)
                {
                    Tile tile = TileSet.GetTile(id);
                    if (tile == null)
                    {
                        continue;
                    }

                    Rectangle rect = new Rectangle(
                        tile.Rectangle.X * (int)ZoomFactor + TextureOffset.X,
                        tile.Rectangle.Y * (int)ZoomFactor + TextureOffset.Y,
                        tile.Rectangle.Width * (int)ZoomFactor,
                        tile.Rectangle.Height * (int)ZoomFactor);

                    Batch.DrawRectangle(rect, SurroundTileColor);

                    Batch.DrawString(BMFont, rect.Location, SurroundTileColor, id.ToString());
                }
            }



            Batch.End();
            GLTextureControl.SwapBuffers();
        }