Exemplo n.º 1
0
        public void Draw(GLViewControl gl)
        {
            RSDKv5Color rcolor1 = Editor.Instance.Scene.EditorMetadata.BackgroundColor1;
            RSDKv5Color rcolor2 = Editor.Instance.Scene.EditorMetadata.BackgroundColor2;

            Color color1 = Color.FromArgb(rcolor1.A, rcolor1.R, rcolor1.G, rcolor1.B);
            Color color2 = Color.FromArgb(rcolor2.A, rcolor2.R, rcolor2.G, rcolor2.B);

            // Draw with first color everything
            if (vb1 == null)
            {
                using (var c = new VBCreator())
                {
                    c.AddRectangle(new Rectangle(0, 0, width, height));
                    vb1 = c.GetVertices();
                }
            }
            vb1.Draw(PrimitiveType.Quads, color1);

            if (color2.A != 0)
            {
                if (vb2 == null)
                {
                    using (var c = new VBCreator())
                    {
                        for (int y = 0; y < DivideRoundUp(height, BOX_SIZE * EditorLayer.TILE_SIZE); ++y)
                        {
                            for (int x = 0; x < DivideRoundUp(width, BOX_SIZE * EditorLayer.TILE_SIZE); ++x)
                            {
                                if ((x + y) % 2 == 1)
                                {
                                    c.AddRectangle(new Rectangle(x * BOX_SIZE * EditorLayer.TILE_SIZE, y * BOX_SIZE * EditorLayer.TILE_SIZE, BOX_SIZE * EditorLayer.TILE_SIZE, BOX_SIZE * EditorLayer.TILE_SIZE));
                                }
                            }
                        }
                        vb2 = c.GetVertices();
                    }
                }
                GL.PushMatrix();
                GL.Translate(0, 0, Editor.LAYER_DEPTH / 2);
                vb2.Draw(PrimitiveType.Quads, color2);
                GL.PopMatrix();
            }
        }
 public void DisposeGraphics(GLViewControl gl)
 {
     gl.MakeCurrent();
     foreach (var vbos in chunks)
     {
         foreach (var vbo in vbos)
         {
             vbo.TexCoords.Destroy();
             vbo.Vertices.Destroy();
         }
     }
     foreach (var vbos in selectedChunks)
     {
         foreach (var vbo in vbos)
         {
             vbo.TexCoords.Destroy();
             vbo.Vertices.Destroy();
             vbo.SelectIndices.Destroy();
         }
     }
     selectedOOB.TexCoords.Destroy();
     selectedOOB.Vertices.Destroy();
     selectedOOB.SelectIndices.Destroy();
 }
        public void Draw(GLViewControl g)
        {
            byte Transperncy = (Editor.Instance.EditLayer != null && Editor.Instance.EditLayer != this) ? (byte)0x32 : (byte)0xFF;

            if (texture == null)
            {
                texture = Texture2D.CreateTexture(Editor.Instance.StageTiles.Image.Bitmap);
            }
            GL.Enable(EnableCap.Texture2D);
            texture.Bind();

            GL.PushAttrib(AttribMask.CurrentBit);

            GL.Color4((byte)255, (byte)255, (byte)255, Transperncy);
            for (int y = 0; y < chunks.Length; ++y)
            {
                for (int x = 0; x < chunks[0].Length; ++x)
                {
                    UpdateChunkVBO(x, y);

                    chunks[y][x].Vertices.Load();
                    chunks[y][x].TexCoords.Load();
                    GL.DrawArrays(PrimitiveType.Quads, 0, chunks[y][x].Vertices.Count);
                    chunks[y][x].Vertices.Unload();
                    chunks[y][x].TexCoords.Unload();
                }
            }
            GL.Disable(EnableCap.Texture2D);

            GL.Color4(System.Drawing.Color.BlueViolet.R, System.Drawing.Color.BlueViolet.G, System.Drawing.Color.BlueViolet.B, Transperncy);
            GL.LineWidth(1.0f);
            for (int y = 0; y < chunks.Length; ++y)
            {
                for (int x = 0; x < chunks[0].Length; ++x)
                {
                    if (SelectedTiles.IsChunkUsed(x, y) || TempSelectionTiles.IsChunkUsed(x, y))
                    {
                        UpdateSelectedChunkVBO(x, y);

                        if (dragging)
                        {
                            GL.PushMatrix();
                            GL.Translate(draggedDistance.X * TILE_SIZE, draggedDistance.Y * TILE_SIZE, Editor.LAYER_DEPTH / 2);
                        }

                        GL.Enable(EnableCap.Texture2D);
                        selectedChunks[y][x].Vertices.Load();
                        selectedChunks[y][x].TexCoords.Load();
                        GL.DrawArrays(PrimitiveType.Quads, 0, selectedChunks[y][x].Vertices.Count);
                        selectedChunks[y][x].TexCoords.Unload();
                        GL.Disable(EnableCap.Texture2D);

                        GL.PushMatrix();
                        GL.Translate(0, 0, Editor.LAYER_DEPTH / 4);
                        selectedChunks[y][x].SelectIndices.Load();
                        GL.DrawElements(PrimitiveType.Lines, selectedChunks[y][x].SelectIndices.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
                        selectedChunks[y][x].SelectIndices.Unload();
                        selectedChunks[y][x].Vertices.Unload();
                        GL.PopMatrix();

                        if (dragging)
                        {
                            GL.PopMatrix();
                        }
                    }
                }
            }
            if (dragging)
            {
                UpdateSelectedOOBVBO();

                GL.PushMatrix();
                GL.Translate(draggedDistance.X * TILE_SIZE, draggedDistance.Y * TILE_SIZE, Editor.LAYER_DEPTH / 2);

                GL.Enable(EnableCap.Texture2D);
                selectedOOB.Vertices.Load();
                selectedOOB.TexCoords.Load();
                GL.DrawArrays(PrimitiveType.Quads, 0, selectedOOB.Vertices.Count);
                selectedOOB.TexCoords.Unload();
                GL.Disable(EnableCap.Texture2D);

                GL.PushMatrix();
                GL.Translate(0, 0, Editor.LAYER_DEPTH / 4);
                selectedOOB.SelectIndices.Load();
                GL.DrawElements(PrimitiveType.Lines, selectedOOB.SelectIndices.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
                selectedOOB.SelectIndices.Unload();
                selectedOOB.Vertices.Unload();
                GL.PopMatrix();

                GL.PopMatrix();
            }

            GL.PopAttrib();

            texture.Unbind();
        }