I am trying to display a bitmap image to an OpenGL control called GL (I am using SharpGL as the wrapper). In practice, a text string is written to a GDI+ Picture box from which the Bitmap is obtained. The GLBitmap function requires a Byte() array as input; I convert the Bitmap to a Byte() array. Does not seem to work as I get a bunch of dots on screen. I have also saved the PictureBox image to a Bmp file on disk and cross-checked that it had the desired content. So, the Bmp image does not appear to be the issue here.
Actual OpenGL display
Bmp file created from the code below
Wondering what I am doing wrong. Anybody would have a suggestion ? Thanks in advance.
The VB.Net code appears below.
' Create Bitmap & Graphics context for string
'
' iWidth and iHeight are the dimensions of the bitmap;
' they are a power of 2.
Dim SharpBMap As Bitmap = New Bitmap(iWidth, iHeight)
Dim SharpGraf As Graphics = Graphics.FromImage(SharpBMap)
' Draw text string to SharpGraf PictureBox
'
SharpGraf.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
SharpGraf.Clear(Color.White)
SharpGraf.DrawString(TxtStr, CurrFont, CurrBrush, 0, 0, CurrFormat)
' OutSharpGL is the Picture box to which the text string is sent
OutSharpGL.Image = SharpBMap
' Save the bitmap to disk: when the file is viewed, the image is Ok.
SharpBMap.Save(FilNameStr)
' Set the color
Gl.Color(1.0f, 1.0f, 1.0f)
' Set the Raster position
Gl.RasterPos(0, 0)
' Transfer the Bitmap
Gl.Bitmap(iWidth, iHeight, 0.0f, 0.0f, 0.0f, 0.0f, BitmapToByte(SharpBMap))
' Function to convert a Bitmap to a Byte() array
Friend Function BitmapToByte(ByRef Bmp As Bitmap) As Byte()
Dim converter As New ImageConverter()
Return DirectCast(converter.ConvertTo(Bmp, GetType(Byte())), Byte())
End Function