Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Having problems with glBitmap

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2008
    Location
    California
    Posts
    15

    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));
    }

    byte[] parts = convertBitmapToBytes(mTextBitmap);

    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);
    gr.glBitmap(mTextBitmap.Width, mTextBitmap.Height, 0, 0, Convert.ToSingle(mTextBitmap.Width), 0, parts);
    gr.glPopAttrib();
    gr.glPopMatrix();
    gr.glMatrixMode(GR.GL_PROJECTION);
    gr.glPopMatrix();

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2008
    Location
    California
    Posts
    15

    Re: Having problems with glBitmap

    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);
    raster = 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);
    }

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2004
    Posts
    205

    Re: Having problems with glBitmap

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2008
    Location
    California
    Posts
    15

    Re: Having problems with glBitmap

    What do you suggest using instead of glBitmap?

  5. #5
    Junior Member Newbie
    Join Date
    May 2011
    Location
    Italy
    Posts
    16

    Re: Having problems with glBitmap

    you could use point sprites

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Having problems with glBitmap

    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.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  7. #7
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Having problems with glBitmap

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •