Ejemplo n.º 1
0
        protected virtual void renderTexture(GuiShader shader, GuiTexture tex, Vector2 scale, int x, int y)
        {
            shader.start();
            GL.BindVertexArray(GuiRenderer.GUIquad.vaoID);
            GL.EnableVertexAttribArray(0);
            var unit = new Vector2(1f / Game.INSTANCE.ClientSize.Width, 1f / Game.INSTANCE.ClientSize.Height);

            float width  = tex.textureSize.Width;
            float height = tex.textureSize.Height;

            float scaledWidth  = width * scale.X;
            float scaledHeight = height * scale.Y;

            float posX = x + scaledWidth / 2;
            float posY = -y - scaledHeight / 2;

            var pos = new Vector2(posX, posY) * unit;

            var mat = MatrixHelper.createTransformationMatrix(pos * 2 - Vector2.UnitX + Vector2.UnitY, scale * new Vector2(width, height) * unit);

            shader.loadTransformationMatrix(mat);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, tex.textureID);
            GL.DrawArrays(shader.renderType, 0, 4);
            GL.DisableVertexAttribArray(0);
            GL.BindVertexArray(0);
            shader.stop();
        }
Ejemplo n.º 2
0
        public void render(Gui gui)
        {
            if (gui == null)
            {
                return;
            }

            shader.start();

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.DepthTest);

            GL.BindVertexArray(GUIquad.vaoID);
            GL.EnableVertexAttribArray(0);

            var state = OpenTK.Input.Mouse.GetCursorState();
            var mouse = Game.INSTANCE.PointToClient(new Point(state.X, state.Y));

            gui.render(shader, mouse.X, mouse.Y);

            GL.DisableVertexAttribArray(0);
            GL.BindVertexArray(0);

            GL.Enable(EnableCap.DepthTest);

            shader.stop();
        }