Exemple #1
0
        private unsafe void AddTestNode(Scene scene)
        {
            Shader shader  = new Shader(GameWindow.SHADER_PATH + "Vert2DColorUVShader.glsl", GameWindow.SHADER_PATH + "pointTexFragShader.glsl");
            var    texture = new Texture("Arrow.png");
            var    node    = new Node {
                Position = new Vector3(0, 0, -3)
            };

            node.Model = Matrix4.CreateTranslation(node.Position);

            VTest2 quad = new VTest2();

            quad.PX1 = -0.5f; quad.PY1 = -0.5f; quad.U1 = 0f; quad.V1 = 1f; quad.r1 = 0xff; quad.g1 = 0xff; quad.b1 = 0xff; quad.a1 = 0xff;
            quad.PX2 = 0.5f; quad.PY2 = -0.5f; quad.U2 = 1f; quad.V2 = 1f; quad.r2 = 0x00; quad.g2 = 0x00; quad.b2 = 0xff; quad.a2 = 0xff;
            quad.PX3 = -0.5f; quad.PY3 = 0.5f; quad.U3 = 0f; quad.V3 = 0f; quad.r3 = 0x00; quad.g3 = 0xff; quad.b3 = 0x00; quad.a3 = 0xff;
            quad.PX4 = 0.5f; quad.PY4 = 0.5f; quad.U4 = 1f; quad.V4 = 0f; quad.r4 = 0xff; quad.g4 = 0x00; quad.b4 = 0x00; quad.a4 = 0xff;
            Vertex2DColorUV vertex       = new Vertex2DColorUV();
            var             buffer       = Serialize(quad);
            var             vertexBuffer = new VertexBuffer <Vertex2DColorUV>(buffer, sizeof(VTest2), vertex.GetVertexFormat());

            uint[] indices = new uint[6] {
                0, 1, 2, 2, 1, 3
            };
            var indexBuffer = new IndexBuffer(indices);
            var renderer    = new Renderer(vertexBuffer, indexBuffer, shader);

            renderer.AddTexture(texture);
            renderer.BlendingFlag = true;
            renderer.CullFaceFlag = false;
            node.Add(renderer);
            scene.Add(node);
        }
Exemple #2
0
        private unsafe void AddTestNode1(Scene scene)
        {
            Shader shader  = new Shader(GameWindow.SHADER_PATH + "Vert2DColorUVShader.glsl", GameWindow.SHADER_PATH + "4channelFragShader.glsl");
            var    texture = new Texture("CellCorner.png");
            var    node    = new Node {
                Position = new Vector3(0, 0, -3)
            };

            node.Model = Matrix4.CreateTranslation(node.Position);

            Vertex2DColorUV[] quad = new Vertex2DColorUV[4]
            {
                // Texture coords - top is 0, bottom is 1
                new Vertex2DColorUV(new Vector2(-0.5f, -0.5f), new Vector2(0, 1), Vertex2DColorUV.WHITE),
                new Vertex2DColorUV(new Vector2(0.5f, -0.5f), new Vector2(1, 1), Vertex2DColorUV.WHITE),
                new Vertex2DColorUV(new Vector2(-0.5f, 0.5f), new Vector2(0, 0), Vertex2DColorUV.WHITE),
                new Vertex2DColorUV(new Vector2(0.5f, 0.5f), new Vector2(1, 0), Vertex2DColorUV.WHITE),
            };

            uint[] indices = new uint[6] {
                0, 1, 2, 2, 1, 3
            };
            var indexBuffer = new IndexBuffer(indices);

            var vertexBuffer = new VertexBuffer <Vertex2DColorUV>(quad);
            var renderer     = new Renderer(vertexBuffer, indexBuffer, shader);

            renderer.AddTexture(texture);
            renderer.BlendingFlag = true;
            node.Add(renderer);
            scene.Add(node);
        }
Exemple #3
0
        public unsafe void RenderDrawData(ImDrawDataPtr drawData, int displayW, int displayH)
        {
            // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.

            int last_texture;

            GL.GetInteger(GetPName.TextureBinding2D, out last_texture);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.ScissorTest);

            // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
            var io = ImGui.GetIO();

            drawData.ScaleClipRects(io.DisplayFramebufferScale);

            shader.Use();
            Matrix4 modelView  = Matrix4.Identity;
            Matrix4 projection = new Matrix4();

            OrthoCamera(io.DisplaySize.X / io.DisplayFramebufferScale.X, io.DisplaySize.Y / io.DisplayFramebufferScale.Y, ref projection);

            shader.SetUniformMatrix4("modelView", modelView);
            shader.SetUniformMatrix4("projection", projection);
            shader.SetSamplerUniform(0, 0);

            GL.ActiveTexture(TextureUnit.Texture0);

            // Render command lists

            for (int n = 0; n < drawData.CmdListsCount; n++)
            {
                ImDrawListPtr   cmd_list   = drawData.CmdListsRange[n];
                byte *          vtx_buffer = (byte *)cmd_list.VtxBuffer.Data;
                ushort *        idx_buffer = (ushort *)cmd_list.IdxBuffer.Data;
                Vertex2DColorUV vertex     = new Vertex2DColorUV();
                var             sz         = sizeof(Vertex2DColorUV);

                var buffer = new VertexBuffer <Vertex2DColorUV>(vtx_buffer, cmd_list.VtxBuffer.Size * sizeof(Vertex2DColorUV), vertex.GetVertexFormat());
                buffer.Bind(shader);

                for (int cmd_i = 0; cmd_i < cmd_list.CmdBuffer.Size; cmd_i++)
                {
                    ImDrawCmdPtr pcmd = cmd_list.CmdBuffer[cmd_i];
                    if (pcmd.UserCallback != IntPtr.Zero)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        GL.BindTexture(TextureTarget.Texture2D, pcmd.TextureId.ToInt32());
                        GL.Scissor((int)pcmd.ClipRect.X,
                                   (int)(io.DisplaySize.Y - pcmd.ClipRect.W),
                                   (int)(pcmd.ClipRect.Z - pcmd.ClipRect.X),
                                   (int)(pcmd.ClipRect.W - pcmd.ClipRect.Y));

                        GL.DrawElements(PrimitiveType.Triangles, (int)pcmd.ElemCount, DrawElementsType.UnsignedShort, new IntPtr(idx_buffer));
                    }
                    idx_buffer += pcmd.ElemCount;
                }
            }

            // Restore modified state
            GL.BindTexture(TextureTarget.Texture2D, last_texture);
            GL.Disable(EnableCap.ScissorTest);
        }