/// <summary> /// Draws the specified string to the backing store. /// </summary> /// <param name="text">The <see cref="System.String"/> to draw.</param> /// <param name="font">The <see cref="System.Drawing.Font"/> that will be used.</param> /// <param name="brush">The <see cref="System.Drawing.Brush"/> that will be used.</param> /// <param name="point">The location of the text on the backing store, in 2d pixel coordinates. /// The origin (0, 0) lies at the top-left corner of the backing store.</param> public void DrawString(string text, System.Drawing.Font font, Brush brush, Point point, StringFormat format) { if (Configuration.RunningOnMono) { // from https://stackoverflow.com/questions/5167937/ugly-looking-text-problem m_Graphics.DrawString(text, font, Brushes.White, new System.Drawing.Point(point.X, point.Y), format); // render text on the bitmap var lockData = m_Bitmap.LockBits(new System.Drawing.Rectangle(0, 0, m_Bitmap.Width, m_Bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { // Pointer to the current pixel uint *pPixel = (uint *)lockData.Scan0; // Pointer value at which we terminate the loop (end of pixel data) var pLastPixel = pPixel + m_Bitmap.Width * m_Bitmap.Height; uint pixelValue, brightness; while (pPixel < pLastPixel) { // Get pixel data pixelValue = *pPixel; // Average RGB brightness = (((pixelValue & 0xff) + ((pixelValue >> 8) & 0xff) + ((pixelValue >> 16) & 0xff)) * 21845) >> 16; // Division by 3 // Use brightness for alpha value, set R, G, and B 0xff (white) pixelValue = brightness << 24 | 0xffffff; // Copy back to image *pPixel = pixelValue; // Next pixel pPixel++; } } m_Bitmap.UnlockBits(lockData); } else { m_Graphics.DrawString(text, font, brush, new System.Drawing.Point(point.X, point.Y), format); // render text on the bitmap } OpenTKBase.LoadTextureInternal(m_Texture, m_Bitmap); // copy bitmap to gl texture }
/// <summary> /// Draws the specified string to the backing store. /// </summary> /// <param name="text">The <see cref="System.String"/> to draw.</param> /// <param name="font">The <see cref="System.Drawing.Font"/> that will be used.</param> /// <param name="brush">The <see cref="System.Drawing.Brush"/> that will be used.</param> /// <param name="point">The location of the text on the backing store, in 2d pixel coordinates. /// The origin (0, 0) lies at the top-left corner of the backing store.</param> public void DrawString(string text, System.Drawing.Font font, Brush brush, Point point, StringFormat format) { m_Graphics.DrawString(text, font, brush, new System.Drawing.Point(point.X, point.Y), format); // render text on the bitmap OpenTKBase.LoadTextureInternal(m_Texture, m_Bitmap); // copy bitmap to gl texture }