Exemplo n.º 1
0
        /// <summary>
        ///     Adds a texture to the vertext buffer
        /// </summary>
        /// <param name="texture">Texture to draw</param>
        /// <param name="dc">Coordinates to draw on</param>
        /// <param name="color">Color to use</param>
        /// <param name="isReflection">If true, then color is faded out in y direction</param>
        protected override void _DrawTexture(CD3DTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false)
        {
            //Align the pixels because Direct3D expects the pixels to be the left top corner
            dc.Wx1 -= 0.5f;
            dc.Wy1 -= 0.5f;
            dc.Wx2 -= 0.5f;
            dc.Wy2 -= 0.5f;

            color.A *= CGraphics.GlobalAlpha;
            int c = color.AsColor().ToArgb();
            int c2;

            if (isReflection)
            {
                color.A = 0;
                c2      = color.AsColor().ToArgb();
            }
            else
            {
                c2 = c;
            }

            var vert = new STexturedColoredVertex[4];

            vert[0] = new STexturedColoredVertex(new Vector3(dc.Wx1, -dc.Wy1, dc.Wz), new Vector2(dc.Tx1, dc.Ty1), c);
            vert[1] = new STexturedColoredVertex(new Vector3(dc.Wx1, -dc.Wy2, dc.Wz), new Vector2(dc.Tx1, dc.Ty2), c2);
            vert[2] = new STexturedColoredVertex(new Vector3(dc.Wx2, -dc.Wy2, dc.Wz), new Vector2(dc.Tx2, dc.Ty2), c2);
            vert[3] = new STexturedColoredVertex(new Vector3(dc.Wx2, -dc.Wy1, dc.Wz), new Vector2(dc.Tx2, dc.Ty1), c);
            _AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(dc.Rotation, dc.Wx1, dc.Wx2, dc.Wy1, dc.Wy2));
        }
Exemplo n.º 2
0
        protected override void _DrawTexture(COGLTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false)
        {
            // Align textures to full pixels to reduce artefacts
            dc.Wx1 = (float)Math.Round(dc.Wx1);
            dc.Wy1 = (float)Math.Round(dc.Wy1);
            dc.Wx2 = (float)Math.Round(dc.Wx2);
            dc.Wy2 = (float)Math.Round(dc.Wy2);

            GL.BindTexture(TextureTarget.Texture2D, texture.Name);

            GL.Enable(EnableCap.Blend);

            GL.MatrixMode(MatrixMode.Texture);
            GL.PushMatrix();

            if (Math.Abs(dc.Rotation) > float.Epsilon)
            {
                GL.Translate(0.5f, 0.5f, 0);
                GL.Rotate(-dc.Rotation, 0f, 0f, 1f);
                GL.Translate(-0.5f, -0.5f, 0);
            }

            GL.Begin(PrimitiveType.Quads);

            GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
            GL.TexCoord2(dc.Tx1, dc.Ty1);
            GL.Vertex3(dc.Wx1, dc.Wy1, dc.Wz);

            if (isReflection)
            {
                GL.Color4(color.R, color.G, color.B, 0);
            }
            GL.TexCoord2(dc.Tx1, dc.Ty2);
            GL.Vertex3(dc.Wx1, dc.Wy2, dc.Wz);

            GL.TexCoord2(dc.Tx2, dc.Ty2);
            GL.Vertex3(dc.Wx2, dc.Wy2, dc.Wz);

            if (isReflection)
            {
                GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
            }
            GL.TexCoord2(dc.Tx2, dc.Ty1);
            GL.Vertex3(dc.Wx2, dc.Wy1, dc.Wz);

            GL.End();

            GL.PopMatrix();

            GL.Disable(EnableCap.Blend);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Calculates the texture and world coordinates for drawing the texture in the rect cropping at the the bounds
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="rect">Rect to draw the texture (might stretch the texture)</param>
        /// <param name="bounds">Rect to stay in (might crop the texture)</param>
        /// <param name="drawCoords">Struct for the coordinates</param>
        /// <param name="mirrored">Mirror on y-axis</param>
        /// <returns>True if anything will be dawn</returns>
        protected bool _CalcDrawCoords(TTextureType texture, SRectF rect, SRectF bounds, out SDrawCoords drawCoords, bool mirrored = false)
        {
            drawCoords = new SDrawCoords();
            if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1 || Math.Abs(bounds.H) < 1 || Math.Abs(bounds.W) < 1)
            {
                return(false);
            }

            if (bounds.X >= rect.Right || bounds.Right <= rect.X)
            {
                return(false);
            }

            if (bounds.Y >= rect.Bottom || bounds.Bottom <= rect.Y)
            {
                return(false);
            }

            drawCoords.Tx1 = Math.Max(0, (bounds.X - rect.X) / rect.W * texture.WidthRatio);
            drawCoords.Wx1 = Math.Max(rect.X, bounds.X);
            drawCoords.Tx2 = Math.Min(1, (bounds.Right - rect.X) / rect.W) * texture.WidthRatio;
            drawCoords.Wx2 = Math.Min(rect.Right, bounds.Right);

            drawCoords.Ty1 = Math.Max(0, (bounds.Y - rect.Y) / rect.H * texture.HeightRatio);
            drawCoords.Wy1 = Math.Max(rect.Y, bounds.Y);
            drawCoords.Ty2 = Math.Min(1, (bounds.Bottom - rect.Y) / rect.H) * texture.HeightRatio;
            drawCoords.Wy2 = Math.Min(rect.Bottom, bounds.Bottom);

            if (mirrored)
            {
                float tmp = drawCoords.Ty1;
                drawCoords.Ty1 = drawCoords.Ty2;
                drawCoords.Ty2 = tmp;
            }

            drawCoords.Wz       = rect.Z + CGraphics.ZOffset;
            drawCoords.Rotation = rect.Rotation;

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Calculates the texture and world coordinates for drawing (a part of) the texture in the rect
        /// </summary>
        /// <param name="texture">Texture to draw</param>
        /// <param name="rect">Rect to draw in (might stretch the texture)</param>
        /// <param name="drawCoords">Struct for the coordinates</param>
        /// <param name="mirrored">Mirror on y axis</param>
        /// <param name="begin">Position of the texture to begin drawing (0 &lt;=x&lt;=1)</param>
        /// <param name="end">Position of the texture to end drawing (0 &lt;=x&lt;=1)</param>
        /// <returns>True if anything will be dawn</returns>
        protected bool _CalcDrawCoords(TTextureType texture, SRectF rect, out SDrawCoords drawCoords, bool mirrored = false, float begin = 0, float end = 1)
        {
            drawCoords = new SDrawCoords();
            if (Math.Abs(rect.W) < 1 || Math.Abs(rect.H) < 1)
            {
                return(false);
            }
            if (begin >= 1 || begin >= end)
            {
                return(false);
            }

            Debug.Assert(begin.IsInRange(0, 1) && end.IsInRange(0, 1));

            drawCoords.Tx1 = begin * texture.WidthRatio;
            drawCoords.Wx1 = rect.X + begin * rect.W;
            drawCoords.Tx2 = end * texture.WidthRatio;
            drawCoords.Wx2 = rect.X + end * rect.W;

            drawCoords.Ty1 = 0;
            drawCoords.Wy1 = rect.Y;
            drawCoords.Ty2 = texture.HeightRatio;
            drawCoords.Wy2 = rect.Bottom;

            if (mirrored)
            {
                float tmp = drawCoords.Ty1;
                drawCoords.Ty1 = drawCoords.Ty2;
                drawCoords.Ty2 = tmp;
            }

            drawCoords.Wz       = rect.Z + CGraphics.ZOffset;
            drawCoords.Rotation = rect.Rotation;

            return(true);
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Adds a texture to the vertext buffer
 /// </summary>
 /// <param name="texture">Texture to draw</param>
 /// <param name="dc">Coordinates to draw on</param>
 /// <param name="color">Color to use</param>
 /// <param name="isReflection">If true, then color is faded out in y direction</param>
 protected abstract void _DrawTexture(TTextureType texture, SDrawCoords dc, SColorF color, bool isReflection = false);