Advertisement

noob question about Lesson 13

Started by July 20, 2003 10:07 PM
8 comments, last by JohnyB 21 years, 7 months ago
How can I change the text color using bitmap fonts? I already tried using something like: glColor3f(1.0f,0.0f,0.0f); glPrint("Something here..."); ...but that doesn''t work It''s that the way it should work or I''m I doing something wrong? Please bear with me I''m a noob to OpenGL...
change the color on the bitmap.
glColor doesn''t work on textures.
Advertisement
How do you mean it doesn''t work? Can you see any text at all, or is the colour just wrong?

I just downloaded lesson #13 and it changes colour fine, ie:

glColor3f(0,0,1); // blue text
glRasterPos2f(10,10); // position of text
glPrint(''Hello World.''); // draw the text

--
Cheers,
--
Cheers,
Darren Clark
I''m getting a very dark green and that''s it...Here''s the code that builds the font...
GLvoid glBuildFont(int font_size){ HFONT font; HFONT oldfont;  base = glGenLists(96);   font = CreateFont(    -(font_size),                         0,                          0,                          0,                         FW_BOLD,                          FALSE,                          FALSE,                         FALSE,                         DEFAULT_CHARSET,                          OUT_TT_PRECIS,                          CLIP_DEFAULT_PRECIS,                         ANTIALIASED_QUALITY,                         FF_DONTCARE|DEFAULT_PITCH,                          "Ms Sans Serif");    oldfont = (HFONT)SelectObject(hDC,font);   wglUseFontBitmaps(hDC,32,96,base);   SelectObject(hDC,oldfont);   DeleteObject(font);}


and here''s the glPrint function...

GLvoid glPrint(float x,float y,const char *string,...){  char text[256];  va_list ap;    if(string == NULL) return;    glRasterPos2f(x,y);    va_start(ap, string);   vsprintf(text,string,ap);  va_end(ap);    glPushAttrib(GL_LIST_BIT);  glListBase(base - 32);    glCallLists(strlen(text),GL_UNSIGNED_BYTE,text);  glPopAttrib();}


Can you see any errors? Should I change something?

i thought you said bitmap, well in that case add the
glColor3f(1.0f,0.0f,0.0f);
before glRasterPos2f(x,y);

and

glColor3f(1.0f,1.0f,1.0f); at the end of the function.
Disable texturing and lighting before drawing the fonts...
Advertisement
Yeah I forgot to mention I was disabling texturing, lighting and blending so it wouldn''t affect the text...if I don''t do this the text comes out transparent...I tried calling glColor like lc_overlord said but it doesn''t work either I also noticed that if I decide not to call glColor while drawing text it comes out in a normal green if I do call it, then the text becomes a very dark blu, please help...
It worked! What happened was I forgot to disable some stuff and that was messing the font. Anyway I have another question but it's sort of stupid and I don't want to make a new thread for it...When you create the fonts they use up display lists right? So how do I make sure that I don't overwrite the fonts when I'm using them to draw other stuff?

[edited by - JohnyB on July 22, 2003 12:02:06 AM]
Up, Anyone? Just that question and I''ll stop bothering ya...
When you generate display lists, you need an ID... You can tell OpenGL this ID yourself, or make OpenGL give you an ID...
To generate an ID you use the glGenLists function... This will always give you an unused ID, so you won''t overwrite any previous display lists...

This topic is closed to new replies.

Advertisement