public void Draw(List <Line> lines, Line prev, float radius, Color colour, Color border_colour, int lineCount = -1)
        {
            TextureGl tex = CreateTexture(colour, border_colour);

            DrawOGL(lines, radius, tex, prev, lineCount);
            tex.Dispose();
        }
 private void ComputeGreyColour()
 {
     if (texture_grey != null)
     {
         texture_grey.Dispose();
     }
     texture_grey = CreateTexture(m_grey, m_border);
 }
 private void ComputeTagColour()
 {
     if (texture_tag != null)
     {
         texture_tag.Dispose();
     }
     texture_tag = CreateTexture(m_tag, m_border);
 }
示例#4
0
        private void Dispose(bool isDisposing)
        {
            if (isDisposed)
            {
                return;
            }
            isDisposed = true;

            if (TextureGl != null)
            {
                TextureGl.Dispose();
                TextureGl = null;
            }
        }
示例#5
0
        private void add(Vector2 offset)
        {
            pTexture trailTexture = SkinManager.t_cursortrail;

            if (trailTexture == null)
            {
                return;
            }

            float drawSize = trailTexture.DisplayWidth * GameBase.WindowManager.RatioInverse * osu.Input.InputManager.s_Cursor.Scale * osu.Input.InputManager.s_Cursor.VectorScale.X;

            RectangleF texCoordsRect = new RectangleF(0, 0,
                                                      (float)trailTexture.Width / TextureGl.GetPotDimension(trailTexture.Width),
                                                      (float)trailTexture.Height / TextureGl.GetPotDimension(trailTexture.Height));

            int   vertexIndex = currentIndex * 4;
            float fadeTime    = fadeClock + 1f;

            vertexBuffer.Vertices[vertexIndex].Position        = offset + new Vector2(-drawSize / 2, -drawSize / 2);
            vertexBuffer.Vertices[vertexIndex].TexturePosition = new Vector2(0, 0);
            vertexBuffer.Vertices[vertexIndex].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex].Time            = fadeTime;

            vertexBuffer.Vertices[vertexIndex + 1].Position        = offset + new Vector2(-drawSize / 2, drawSize / 2);
            vertexBuffer.Vertices[vertexIndex + 1].TexturePosition = new Vector2(0, texCoordsRect.Height);
            vertexBuffer.Vertices[vertexIndex + 1].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex + 1].Time            = fadeTime;

            vertexBuffer.Vertices[vertexIndex + 2].Position        = offset + new Vector2(drawSize / 2, drawSize / 2);
            vertexBuffer.Vertices[vertexIndex + 2].TexturePosition = new Vector2(texCoordsRect.Width, texCoordsRect.Height);
            vertexBuffer.Vertices[vertexIndex + 2].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex + 2].Time            = fadeTime;

            vertexBuffer.Vertices[vertexIndex + 3].Position        = offset + new Vector2(drawSize / 2, -drawSize / 2);
            vertexBuffer.Vertices[vertexIndex + 3].TexturePosition = new Vector2(texCoordsRect.Width, 0);
            vertexBuffer.Vertices[vertexIndex + 3].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex + 3].Time            = fadeTime;

            fadeTimes[currentIndex]   = fadeTime;
            needsUpload[currentIndex] = true;

            currentIndex = (currentIndex + 1) % MAX_SPRITES;
        }
        /// <summary>
        /// Core drawing method in OpenGL
        /// </summary>
        /// <param name="lineList">List of lines to use</param>
        /// <param name="globalRadius">Width of the slider</param>
        /// <param name="texture">Texture used for the track</param>
        /// <param name="prev">The last line which was rendered in the previous iteration, or null if this is the first iteration.</param>
        private void DrawOGL(List <Line> lineList, float globalRadius, TextureGl texture, Line prev, int lineCount)
        {
            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthMask(true);
            GL.DepthFunc(DepthFunction.Lequal);

            GL.Clear(ClearBufferMask.DepthBufferBit);

            OsuGlControl.TextureShader3D.Begin();

            OsuGlControl.BindTexture(texture.TextureId);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);

            if (lineCount == -1)
            {
                lineCount = lineList.Count;
            }

            for (int x = 1; x < lineCount; x++)
            {
                DrawLineOGL(prev, lineList[x - 1], lineList[x], globalRadius);
                prev = lineList[x - 1];
            }

            DrawLineOGL(prev, lineList[lineCount - 1], null, globalRadius);

            quadBatch.Draw();
            halfCircleBatch.Draw();

            OsuGlControl.TextureShader3D.End();

            GL.Disable(EnableCap.DepthTest);
            GL.DepthMask(false);
            GL.Enable(EnableCap.Blend);
        }
        internal override pTexture CreateText(string text, float size, OpenTK.Vector2 restrictBounds, OpenTK.Graphics.Color4 Color4, bool shadow, bool bold, bool underline, TextAlignment alignment, bool forceAa, out OpenTK.Vector2 measured, OpenTK.Graphics.Color4 background, OpenTK.Graphics.Color4 border, int borderWidth, bool measureOnly, string fontFace)
        {
            //UIFont font = bold ? UIFont.FromName("GillSans-Bold", size) : UIFont.FromName("GillSans",size);
            //UIFont font = bold ? UIFont.BoldSystemFontOfSize(size) : UIFont.SystemFontOfSize(size);
            UIFont font = UIFont.FromName(bold ? "Futura-CondensedExtraBold" : "Futura-Medium",size);

            CGSize actualSize = CGSize.Empty;

            // Render the text to a UILabel to calculate sizing
            // and line-wrapping, and then copy the pixels to our texture buffer.
            UILabel textLabel = new UILabel();
            textLabel.Font = font;
            textLabel.BackgroundColor = UIColor.Clear;
            textLabel.TextColor = UIColor.White;
            textLabel.LineBreakMode = UILineBreakMode.WordWrap;
            textLabel.Lines = 0; // Needed for multiple lines
            textLabel.Text = text;

            textLabel.TextAlignment = UITextAlignment.Left;
            switch (alignment) {
            case TextAlignment.Centre:
                textLabel.TextAlignment = UITextAlignment.Center;
                break;
            case TextAlignment.Right:
                textLabel.TextAlignment = UITextAlignment.Right;
                break;
            }

            if (restrictBounds == Vector2.Zero)
            {
                textLabel.SizeToFit();
                actualSize = textLabel.Frame.Size;

                restrictBounds = new Vector2((float)actualSize.Width, (float)actualSize.Height);
            }
            else if (restrictBounds.Y == 0)
            {
                SizeF boundsSize = new SizeF (restrictBounds.X, GameBase.NativeSize.Height);
                actualSize = textLabel.SizeThatFits(boundsSize);
                textLabel.Frame = new CGRect(CGPoint.Empty, actualSize);

                restrictBounds = new Vector2((float)actualSize.Width, (float)actualSize.Height);
            }

            int width = TextureGl.GetPotDimension((int)restrictBounds.X);
            int height = TextureGl.GetPotDimension((int)restrictBounds.Y);

            IntPtr data = Marshal.AllocHGlobal(width * height);
            unsafe {
                byte* bytes = (byte*)data;
                for (int i = width * height - 1; i >= 0; i--) bytes[i] = 0;
            }

            using (CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray())
            using (CGBitmapContext context = new CGBitmapContext(data, width, height, 8, width, colorSpace,CGImageAlphaInfo.None))
            {
                context.TranslateCTM(0, height);
                context.ScaleCTM(1, -1);

                UIGraphics.PushContext(context);

                textLabel.SetNeedsDisplay();
                textLabel.Layer.DrawInContext (context);
                
                UIGraphics.PopContext();

                measured = new Vector2((float)actualSize.Width, (float)actualSize.Height);

    			SpriteManager.TexturesEnabled = true;

                TextureGl gl = new TextureGl(width, height);
                gl.SetData(data, 0, All.Alpha);

                Marshal.FreeHGlobal(data);

                return new pTexture(gl, (int)actualSize.Width, (int)actualSize.Height);
            }
        }
示例#8
0
        public override bool Draw()
        {
            if (bypass)
            {
                return(false);
            }

            SpriteManager.Current.SetBlending(Additive);

            pTexture texture = Texture;

            if (texture == null || texture.IsDisposed)
            {
                return(true);
            }

            Vector2 d = new Vector2(drawRectangle.X + drawOriginScaled.X, drawRectangle.Y + drawOriginScaled.Y);

            if (vertexBuffer == null)
            {
                vertexBuffer = new QuadVertexBuffer <ParticleVertex2d>(amountParticles, BufferUsageHint.StaticDraw);

                RectangleF texCoordsRect = new RectangleF(0, 0,
                                                          (float)texture.Width / TextureGl.GetPotDimension(texture.Width),
                                                          (float)texture.Height / TextureGl.GetPotDimension(texture.Height));

                for (int i = 0; i < amountParticles; ++i)
                {
                    int vertexIndex = i * 4;

                    int     time      = RNG.Next(500, 1200);
                    double  angle     = RNG.NextDouble(Math.PI * 2.0);
                    Vector2 direction = drawScaleVector * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * (float)RNG.NextDouble(radius);

                    if (time > maxTime)
                    {
                        maxTime = time;
                    }

                    vertexBuffer.Vertices[vertexIndex + 0].Position        = d + new Vector2(-drawRectangle.Width / 2, -drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 0].TexturePosition = new Vector2(0, 0);
                    vertexBuffer.Vertices[vertexIndex + 0].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 0].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 0].Direction       = direction;

                    vertexBuffer.Vertices[vertexIndex + 1].Position        = d + new Vector2(-drawRectangle.Width / 2, drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 1].TexturePosition = new Vector2(0, texCoordsRect.Height);
                    vertexBuffer.Vertices[vertexIndex + 1].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 1].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 1].Direction       = direction;

                    vertexBuffer.Vertices[vertexIndex + 2].Position        = d + new Vector2(drawRectangle.Width / 2, drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 2].TexturePosition = new Vector2(texCoordsRect.Width, texCoordsRect.Height);
                    vertexBuffer.Vertices[vertexIndex + 2].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 2].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 2].Direction       = direction;

                    vertexBuffer.Vertices[vertexIndex + 3].Position        = d + new Vector2(drawRectangle.Width / 2, -drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 3].TexturePosition = new Vector2(texCoordsRect.Width, 0);
                    vertexBuffer.Vertices[vertexIndex + 3].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 3].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 3].Direction       = direction;
                }

                vertexBuffer.Update();
            }

            if (texture.TextureGl != null && texture.TextureGl.Bind())
            {
                OsuGlControl.ParticleShader.Properties[@"g_Gravity"]   = gravity;
                OsuGlControl.ParticleShader.Properties[@"g_FadeClock"] = (float)(getClockTime() - startTime);
                OsuGlControl.ParticleShader.Begin();
                vertexBuffer.Draw();
                OsuGlControl.ParticleShader.End();
            }

            return(true);
        }
示例#9
0
 public pTexture(TextureGl textureGl, TextureAtlas containingAtlas = null)
 {
     Debug.Assert(textureGl != null);
     TextureGl       = textureGl;
     ContainingAtlas = containingAtlas;
 }