Example #1
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Methods
        //---------------------------------------------------------------
        /// <summary>
        /// Draws the text into the specified texture.
        /// </summary>
        /// <param name="text">Text to draw.</param>
        /// <param name="pos">The target position.</param>
        /// <param name="color">Color to preclear the bitmap with.</param>
        public void Draw(string text, Vector2 pos, int color)
        {
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
            // Begin Instead of g.Clear()
            BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            if (data.Stride == data.Width * 4)
            {
                Purple.Tools.Memory.BlockCopy(data.Scan0, color, (data.Stride * data.Height) / 4);
            }
            else
            {
                g.Clear(System.Drawing.Color.FromArgb(color));
            }
            bitmap.UnlockBits(data);
            // End Instead of g.Clear()
            //g.Clear( System.Drawing.Color.FromArgb(color) );
            Draw(g, text, pos);
            g.Dispose();
            texture.CopyBitmap(bitmap, Rectangle.Empty, new Point(0, 0));
        }
Example #2
0
        /// <summary>
        /// loads a texture from a stream containing raw bitmap data
        /// </summary>
        /// <param name="stream">stream to load from</param>
        /// <param name="width">width of texture</param>
        /// <param name="height">height of texture</param>
        /// <param name="mipLevels">number of MipMap level</param>
        /// <param name="format">format of texture</param>
        /// <returns>texture object</returns>
        private ITexture2d LoadRaw(Stream stream, int width, int height, int mipLevels, Purple.Graphics.Format format)
        {
            int countBytes = width * height * Purple.Graphics.GraphicsEngine.BitsPerPixel(format) / 8;

            byte[] data = new Byte[countBytes];
            stream.Read(data, 0, countBytes);

            System.Drawing.Bitmap bitmap;
            // pin array
            System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(data);
            System.IntPtr ptr = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
            bitmap = new System.Drawing.Bitmap(width, height, width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, ptr);

            ITexture2d tex = TextureManager.Instance.Create(width, height, 1, Format.A8R8G8B8, TextureUsage.Normal);

            tex.CopyBitmap(bitmap, new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Point.Empty);
            bitmap.Dispose();
            handle.Free();
            return(tex);
        }