PDA

View Full Version : Having problems with glBitmap



atlasdynamics
07-06-2011, 09:31 AM
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();

atlasdynamics
07-06-2011, 02:41 PM
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);
}

l_belev
07-09-2011, 06:41 AM
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.

atlasdynamics
07-11-2011, 08:23 PM
What do you suggest using instead of glBitmap?

A.Conz
07-12-2011, 05:32 AM
you could use point sprites

V-man
07-13-2011, 07:03 AM
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.

BionicBytes
07-14-2011, 10:04 AM
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.