Jump to content
  • Advertisement
Sign in to follow this  
dpm_dpmartin

OpenGL Beginner's Question: OpenGL and Bitmap Fonts.

This topic is 4404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have spent a couple of weeks tinkering with OpenGL and reading up on all the tutorials available out there - NeHe and Sulaco having exceptionally helpful information for someone just starting out with OpenGL. I am coding in Delphi, but - as everyone says - that shouldn't stop anyone from understanding the OpenGL code in my request for help. I have been cribbing pieces of OpenGL code from different tutorials with the hope of getting good enough with it so that I can consider including OpenGL in my main project to spice it up a bit - it's not a game, but it could do with being more visually appealing I think and what I've so far achieved with OpenGL makes me think I can make my project much better with it. At the moment, I have a moving background, a rotating 3D cube with CD Album covers on it and a bit of text at the bottom of the screen moving back and forth... I have only learned how to do the font today after looking at NeHe's lesson 13. Here is what the finished program looks like: What my program currently looks like As you can see... I want my text to be solid white. Here is some snippets of code from the Draw method - called repeatedly by a TTimer. You will see that I am doing three distinct things - the background, the font and the Album Cube.
  glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity;
  Angle := Angle + 1;
  glTranslatef (0,0,-10);
  glRotatef (Angle / 5,0,0,1);
  glBindTexture (GL_TEXTURE_2D,Background);

  // Do the background display stuff, snipped from here for conciseness.

  // Then go on and do the font stuff...
  glLoadIdentity;
  glTranslatef (-0.04,0.0,-1.0);
  FX := -0.45 + 0.05 * Cos (Angle / 20);
  FY := -0.36;

  // Set to full light, white?
  glColor3f (1,0,0);
  glRasterPos2f (FX,FY);
  glPrint ('White font with drop-shadow..?');

  // Set to no light, black.
  glColor3f (0,0,0);
  glRasterPos2f (FX + 0.005,FY - 0.005);
  glPrint ('White font with drop-shadow..?');

  // Reset to full light, white.
  glColor3f (1,1,1);

  // Then go on and do the Album Cube stuff...
  // This has a glLoadIdentity and glTranslatef (X,Y,Z) section
  // and then loads textures onto each side of the cube.
  AlbumCube (0,0,-6,Flipper1,Flipper2,0);

  SwapBuffers (wglGetCurrentDC);




The issue is that I cannot get the font text to be a solid white. I believe I know why that is, but I don't believe I currently know how to get around it. If I use the code "glColor3f (1,0,0);" before writing the text, it changes colour along with the colour of the background, if I use "glColor3f (1,0,0);" then it is a pretty solid red - but also fades in line with the background. What I want is the background to move around, changing colour, and my font to remain a static colour - white. The black is OK of course - I am using "glColor3f (0,0,0);" for that and I do understand that I'm basically removing all light (pardon the expression, I know there are no OpenGL lights in my example!) intensity to 0, so it will always be black. If anyone could point out the error of my ways I would be most grateful. I am willing and able to provide the full source in a .zip if that is required. This is just a program for my own education before I start using OpenGL in more serious work - but to do that, I need to feel more confident with it first. Maybe there's even a better way of doing a font with a drop-shadow than what I am currently doing... I'm basing my OpenGL tinkering on what I've done in Delphi previously, i.e. writing to a Canvas object with TextOut etc.. [Edited by - dpm_dpmartin on July 29, 2006 1:03:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
why are you writing in your post about what happens when you set "glColor3f (1,0,0);" and then another thing when seting to same "glColor3f (1,0,0);"
which is red color? why you don't set it to "(1,1,1)" (white) before displaying text?

Share this post


Link to post
Share on other sites
Yes, "glColor3f (1,0,0);" is the current code that gets the picture in the image, I kept the code for the image the same to better illustrate to you what had been tried. Hopefully you understand the problem a bit better now... trying "glColor3f (1,1,1);" does not actually get white text for you - nor does "glColor3f (1,0,0);" get you a solid unchanging colour of red. That is kind of the whole point of the post. Please, let me clarify for you...

"glColor3f (1,0,0);" gives you mostly a solid red - but it just has maximum red intensity, and will change colour inline with whatever is showing in the background.

"glColor3f (1,1,1);" gives you the exact colour that is showing in the background. It is not white at all.

If you use "glColor3f (1,1,1);", you get something like this:

Second example with glColor3f (1,1,1)

Maybe now it will be clearer, as you can see - the text is currently a light shade of purple / pink, like the background - it also changes in-line with the background - that is with "glColor3f (1,1,1);" which you advise should get me a white colour - I can assure you that it does not.

Hopefully someone can help me get past this annoying little hurdle. What I need is some way to, say, separate out my objects on the screen so that the font can have its colour / intensity of colour changed by code and it is not affected by the other objects, and it doesn't affect other objects. Hopefully, it is clearer to the reader now. Please let me know if not.

Share this post


Link to post
Share on other sites
An excellent, correct, and succinct, response from Lord Faron.

Adding "glDisable (GL_TEXTURE_2D);" before I start to mess with my text and "glEnable (GL_TEXTURE_2D);" after I finish with it, gets me a solid white font.. regardless of the colour of the background texture.

Many thanks; that had been bugging me - you've helped a learner along there!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!