예제 #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();
        }
예제 #2
0
 public GuiScreenMainMenu()
 {
     buttons.Add(new GuiButton(0, 0, 200, Vector2.One * 2)
     {
         centered = true
     });
     background = new GuiTexture(GraphicsManager.loadTexture("gui/bg", false), Vector2.Zero, Vector2.One * 8);
 }
예제 #3
0
        protected virtual void renderTexture(GuiShader shader, GuiTexture tex)
        {
            var ratio = new Vector2((float)tex.textureSize.Width / Game.INSTANCE.ClientSize.Width, (float)tex.textureSize.Height / Game.INSTANCE.ClientSize.Height);

            var mat = MatrixHelper.createTransformationMatrix(tex.pos * 2, tex.scale * ratio);

            shader.loadTransformationMatrix(mat);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, tex.textureID);
            GL.DrawArrays(shader.renderType, 0, 4);
        }
예제 #4
0
        public GuiRenderer()
        {
            shader = new GuiShader("gui");

            var texture = GraphicsManager.loadTexture("gui/cross", true);

            if (texture != null)
            {
                var tex = new GuiTexture(texture.textureID, texture.textureSize, Vector2.Zero, Vector2.One * 1.4f);
                crosshairGui = new GuiCrosshair(tex);
            }

            hudGui = new GuiHUD();
        }
예제 #5
0
        protected virtual void drawBackground(GuiShader shader, GuiTexture tex)
        {
            var sizeX = tex.textureSize.Width * tex.scale.X;
            var sizeY = tex.textureSize.Height * tex.scale.Y;

            var countX = Game.INSTANCE.ClientSize.Width / sizeX;
            var countY = Game.INSTANCE.ClientSize.Height / sizeY;

            for (int x = 0; x <= countX; x++)
            {
                for (int y = 0; y <= countY; y++)
                {
                    renderTexture(shader, tex, (int)(x * sizeX), (int)(y * sizeY));
                }
            }
        }
예제 #6
0
        public override void render(GuiShader shader, int mouseX, int mouseY)
        {
            GuiTexture tex = GUI_BUTTON;

            if (isMouseOver(mouseX, mouseY))
            {
                tex = GUI_BUTTON_HOVER;
            }

            if (centered)
            {
                posX = (int)(Game.INSTANCE.ClientSize.Width / 2f - tex.textureSize.Width * scale.X / 2f);
                renderTexture(shader, tex, scale, posX, posY);
            }
            else
            {
                renderTexture(shader, tex, scale, posX, posY);
            }
        }
예제 #7
0
 public GuiScreenIngameMenu()
 {
     background = new GuiTexture(GraphicsManager.loadTexture("gui/bg_transparent", false), Vector2.Zero, Vector2.One * 4);
 }
예제 #8
0
 protected virtual void renderTexture(GuiShader shader, GuiTexture tex, int x, int y)
 {
     renderTexture(shader, tex, tex.scale, x, y);
 }
예제 #9
0
 static GuiButton()
 {
     GUI_BUTTON       = new GuiTexture(GraphicsManager.loadTexture("gui/button", false));
     GUI_BUTTON_HOVER = new GuiTexture(GraphicsManager.loadTexture("gui/button_hover", false));
 }
예제 #10
0
 public GuiScreenCrafting()
 {
     gui = new GuiTexture(GraphicsManager.loadTexture("gui/crafting", false), Vector2.One * 0.5f);
 }
예제 #11
0
 public GuiScreen()
 {
     background = new GuiTexture(GraphicsManager.loadTexture("gui/bg", false), Vector2.Zero, Vector2.One * 4);
 }
예제 #12
0
 public GuiCrosshair(GuiTexture crosshairTexture)
 {
     this.crosshairTexture = crosshairTexture;
 }