Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Need to print labels on a GlControl box for a graph. This can be done easily with Glut. However, OpenGL.Net does not seem to support GLUT.

What I have tried:

Tried writing the string on a bitmap and then print it on the Glcontrol but it prints some garbage value.
The application is in WinForm.

The following code was writen in the GlControl.render event's delegate function:

C#
Gl.Clear(ClearBufferMask.ColorBufferBit);
            Gl.ClearColor(1f,1f,1f,0);
            Gl.MatrixMode(MatrixMode.Texture);
            Gl.LoadIdentity();
            Font drFont = new Font("Arial", 10);
            Pen redPen = new Pen(Color.Red, 1);
            SolidBrush drBrush = new SolidBrush(Color.Red);
            Bitmap bmp = new Bitmap(100,100,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            RectangleF rectf = new RectangleF(0, 0, bmp.Width, bmp.Height);

            // Create graphic object that will draw onto the bitmap
            Graphics g = Graphics.FromImage(bmp);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            // The interpolation mode determines how intermediate values between two endpoints are calculated.
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Use this property to specify either higher quality, slower rendering, or lower quality, faster rendering of the contents of this Graphics object.
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;

            // This one is important
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            // Create string formatting options (used for alignment)
            StringFormat format = new StringFormat()
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };  
            g.DrawString("Abc", new Font("Tahoma", 80), Brushes.Black, rectf, format);

            // Flush all graphics changes to the bitmap
            g.Flush();
            ImageConverter i = new ImageConverter();
            byte[] b = (byte[])i.ConvertTo(bmp, typeof(byte[]));
            Gl.RasterPos3(0, 0, 0);
            Gl.Bitmap(100, 100, 0, 0, 0, 0, b);



Thanks in Advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900