Hi, I am trying to create a font using glDrawPixels rather than glBitmap. I
cannot move the x position more than one time through the glRasterPos2i...
Should I be moving the rasterposition during the drawing...
I guess the code will lokk familiar too many examples, perhaps someone may
show me any redundant calls made also...
Thanks in advance, Cam
void __fastcall TTelGLFont2d::Create()
{
try
{
int cnt,i,wd,ht,pos;
long pixel;
int dst;
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
ListBase = glGenLists(lastglyph);
cnt = rectlist->Count;
for (i = 0; i < cnt; i++)
{
TTelRect* rect = rectlist->Items[i];
wd = rect->Width;
ht = rect->Height;
GLubyte* data = new GLubyte[(wd*ht*4)];
for (int h = 0; h < ht; h++)
{
for (int w = 0; w < wd; w++)
{
pixel=rect->Character->Canvas->Pixels[w][(ht-h)-1];
pos=(h*wd*4)+(w*4);
data[pos+0] = GetRValue(pixel);
data[pos+1] = GetGValue(pixel);
data[pos+2] = GetBValue(pixel);
data[pos+3] = 255;
}
}
glNewList(i+ListBase, GL_COMPILE);
glBegin();
GLint* rpos = new GLint[4];
glGetIntegerv(GL_CURRENT_RASTER_POSITION,rpos);
glRasterPos2i(rpos[0]+wd,0);
delete rpos;
glDrawPixels(wd,ht,GL_RGBA,GL_UNSIGNED_BYTE,data);
glEndList();
delete data;
}
}
void __fastcall TTelGLFont2d::Draw(AnsiString Text)
{
unsigned char *c=(unsigned char *)Text.c_str();
int Index;
int Length=strlen((char *)c);
glDisable(GL_DEPTH_TEST); // Disables Depth Testing
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPushMatrix(); // Store The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glOrtho(0,640,0,480,-1,1); // Set Up An Ortho Screen
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPushMatrix(); // Store The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
// glTranslated(10.0,10.0,0); // Position The Text (0,0 - Bottom Left)
glListBase(ListBase-32); // Choose The Font Set (0 or 1)
glCallLists(Length,GL_BYTE,c); // Write The Text To The Screen
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glEnable(GL_DEPTH_TEST); // Enables Depth Testing