Having problems with glBitmap

I can’t get text to render correctly with this code. What displays are dots and dashes in streeks.

System.Drawing.Bitmap mTextBitmap = new Bitmap(TextWidth, TextHeight);
using (Graphics g = Graphics.FromImage(mTextBitmap))
{
g.Clear(Transparency);
SolidBrush TextClr = new SolidBrush(TextColor);
SizeF extent = new SizeF(0, 0);
mTextBitmap.MakeTransparent(Transparency);
Font aFont = AppropriateFont(g, 0.0f, 50.0f, mTextBitmap.Size, Text, new Font(FontName, 50.0f), out extent);
g.DrawString(Text, aFont, TextClr, new PointF(0.0f, 0.0f));
}

    [b]byte[] parts = convertBitmapToBytes(mTextBitmap);[/b]
    gr.glMatrixMode(GR.GL_PROJECTION);
    gr.glPushMatrix();
    gr.glLoadIdentity();
    gr.glOrtho
    (
        (double)0,
        clientWidth - 1.0,
        (double)0,
        clientHeight - 1,
        -1.0,
        1.0
    );
    gr.glMatrixMode(GR.GL_MODELVIEW);
    gr.glLoadIdentity();
    gr.glRasterPos2d(location[0], location[1]);//glWindowPos2dv(location);
    gr.glPixelStorei(GR.GL_UNPACK_ALIGNMENT, 1);
    gr.glPushAttrib(GR.GL_LIST_BIT);
    [b]gr.glBitmap(mTextBitmap.Width, mTextBitmap.Height, 0, 0, Convert.ToSingle(mTextBitmap.Width), 0, parts);[/b]
    gr.glPopAttrib();
    gr.glPopMatrix();
    gr.glMatrixMode(GR.GL_PROJECTION);
    gr.glPopMatrix();

I changed the code so it uses the bitmap for each character stored in the calllist. The MakeRasterFont is called to build the bitmaps of characters and store them in a calllist. The variable raster in MakeRasterFont is a byte array. DrawBitMapCharacter is used to place the chacters on the raster but no characters will render. Does anyone have an idea as to why?

public static void MakeRasterFont(GR gl, String FontName, int TextWidth, int TextHeight, ref int fontOffset)
{
fontOffset = gl.glGenLists(256);
gl.glPixelStorei(GR.GL_UNPACK_ALIGNMENT, 1);
Byte raster = null;

    for (byte i = 0; i < 254; i++)
    {
        gl.glNewList(i + fontOffset, GR.GL_COMPILE);
        [b]raster[/b] = DrawAplahCharMap(gl, (char)i, FontName, TextWidth, TextHeight);
        gl.glBitmap(TextWidth, TextHeight, 0.0f, 0.0f, TextWidth, 0.0f, raster);
        gl.glEndList();
    }
}

public static byte DrawAplahCharMap(GR gr, Char Text, String FontName, int TextWidth, int TextHeight)
{
System.Drawing.Bitmap mTextBitmap = new Bitmap(TextWidth, TextHeight);
using (Graphics g = Graphics.FromImage(mTextBitmap))
{
g.Clear(Color.Transparent);
SolidBrush TextClr = new SolidBrush(Color.Black);
SizeF extent = new SizeF(0, 0);
mTextBitmap.MakeTransparent(Color.Transparent);
Font aFont = AppropriateFont(g, 0.0f, 50.0f, mTextBitmap.Size, Text.ToString(), new Font(FontName, 50.0f), out extent);
g.DrawString(Text.ToString(), aFont, TextClr, new PointF(0.0f, 0.0f));
}
return convertBitmapToBytes(mTextBitmap);

}

public static void DrawBitMapCharacter(GR gr, String Text, int fontOpenGLDisplayListBaseIndex, Double location, int SourceFactor, int DestinationFactor)
{

    gr.glPushMatrix();
    gr.glRasterPos2d(location[0], location[1]);// glWindowPos2dv(location);
    gr.glEnable(GR.GL_BLEND);
    gr.glBlendFunc(SourceFactor, DestinationFactor);
    int stringLength = Text.Length;
    gr.glPushAttrib(GR.GL_LIST_BIT);
    for
    (
        int stringCharacterIndex = 0;
        stringCharacterIndex < stringLength;
        stringCharacterIndex++
    )
    {
        int ASCIICharacter = (int)(Text[stringCharacterIndex]);
        gr.glCallList(fontOpenGLDisplayListBaseIndex + ASCIICharacter);
    }
    gr.glPopAttrib();
    gr.glPopMatrix();
    gr.glDisable(GR.GL_BLEND);
}

I would advise against using such long obsolete things as glBitmap.
They are likely to be neglected by the driver writers and who knows what driver bugs you can come across.

What do you suggest using instead of glBitmap?

you could use point sprites

The modern way is to make a texture (or textures) out of your data and then render them with quads.
For the format of the texture, I suggest GL_RGBA8.

render them with quads.

You mean triangles. Core profile does not allow quads.
Of course with combatibility profile (which most people use) you can still use quads.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.