🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

I can't get my font size to change??

Started by
11 comments, last by vivekd 18 years, 5 months ago
Hello, I've been going through the NeHE Lessons and I am now on Lesson 13. I can get it to run fine but when I try to change the size of the font It will not get smaller or bigger... I've looked at the documentation on msdn and searched google on the CreateFont function and i'm getting no luck... I'm looking for a pointer as to why my text won't change size.. Here is the code I am using...

GLvoid BuildFont(bool outline) {
       HFONT font;
       HFONT oldFont;
       
       // int PointSize = 0;
       // int nHeight = -MulDiv(PointSize, GetDeviceCaps(_pGame->GetHDC(), 
       //              LOGPIXELSY), 72);
       
       if (outline == true) { // Comic Sans MS
          MessageBox(NULL, "Outline", "Outline", MB_OK);
          base = glGenLists(256);
          font = CreateFont(-12,0,0,0,FW_BOLD,false,false,false,ANSI_CHARSET,
                             OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,
                             FF_DONTCARE | DEFAULT_PITCH,"Comic Sans MS");
       }
       else {
            MessageBox(NULL, "Bitmap", "Bitmap", MB_OK);
           base = glGenLists(96);
           font = CreateFont(-24,0,0,0,FW_BOLD,false,false,false,ANSI_CHARSET,
                             OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,
                             FF_DONTCARE | DEFAULT_PITCH,"Courier New");
       }
       
       oldFont = (HFONT)SelectObject(_pGame->GetHDC(),font);
       
       if (outline == true) {
          MessageBox(NULL, "Outline", "Outline", MB_OK);
          wglUseFontOutlines(_pGame->GetHDC(),0,255,base,0.0f,0.2f,
                            WGL_FONT_POLYGONS,gmf);
       }
       else {
            MessageBox(NULL, "Bitmap", "Bitmap", MB_OK);
            wglUseFontBitmaps(_pGame->GetHDC(),32,96,base);
       }
       
       SelectObject(_pGame->GetHDC(),oldFont);
       DeleteObject(font);
}


GLvoid glPrint(bool outline, const char *fmt, ...) {
       
       float   lenght = 0;
       char    text[256];
       va_list ap;
       
       if (fmt == NULL) {
          return;
       }
       
       va_start(ap,fmt);
           vsprintf(text,fmt,ap);
       va_end(ap);
       
       for (unsigned int loop = 0; loop < (strlen(text)); loop++) {
           lenght += gmf[text[loop]].gmfCellIncX;
       }
       
       glTranslatef(-lenght/2,0.0f,0.0f);
       
       glPushAttrib(GL_LIST_BIT);
       
       if (outline) {
          glListBase(base);
       }
       else {
            glListBase(base - 32);
       }
       
       glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
       glPopAttrib();
}


int DrawGLScene(GLvoid) {                             // Heres where we do ALL the drawing
       
       // Clear the screen and the depth buffer
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       glLoadIdentity();
       
       DrawMap();
       
       
       glEnable(GL_COLOR_MATERIAL);
       glEnable(GL_LIGHTING);
       glTranslatef(0.0f,0.0f,-1.5f);
       glColor3f(1.0f,1.0f,0.0f);
       glPrint(true, "Lotas - %3.2f", rot/50);
       glDisable(GL_COLOR_MATERIAL);
       glDisable(GL_LIGHTING);
       
       glColor3f(1.0f,1.0f,1.0f);
       
       rot += 0.1f;
       
       return true;                                   // Everything went OK
}


int initGL(GLvoid) {                                  // All setup for openGL goes here
       
       // Start Of User Initialization
       if (!LoadBitmap("Data/wall.bmp", texture[0], GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, 1)) // Load The Bitmap
		  return FALSE;
       if (!LoadBitmap("Data/floor.bmp", texture[1], GL_LINEAR, GL_LINEAR, 0)) // Load The Bitmap
		  return FALSE;	
       if (!LoadBitmap("Data/ceiling.bmp", texture[2], GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, 1)) // Load The Bitmap
		  return FALSE;
       if (!LoadBitmap("Data/lobManga5.bmp", texture[3], GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, 1)) // Load The Bitmap
		  return FALSE;
       if (!LoadBitmap("Data/door1.bmp", texture[4], GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, 1)) // Load The Bitmap
		  return FALSE;
       if (!LoadBitmap("Data/Glass.bmp", texture[5], GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, 1)) // Load The Bitmap
		  return FALSE;
       
       // glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
       
       glEnable(GL_TEXTURE_2D);                       // Enable Texture mapping
       glBlendFunc(GL_SRC_ALPHA, GL_ONE);
       glClearColor(0.0f,0.0f,0.0f,0.0f);             // Black Background
       glClearDepth(1.0f);                            // Depth Buffer setup
       glDepthFunc(GL_LEQUAL);                        // The type of Depth Test to do
       glEnable(GL_DEPTH_TEST);                       // Enable Depth Testing
       glShadeModel(GL_SMOOTH);                       // Enable smooth shading
       // Really nice perspective calculations
       glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
       
       glEnable(GL_LIGHT0);
       
       
       
       BuildFont(true);
       
       SetupWorld();
       
       return true;                                   // Initialization went OK
}

I'm trying to add some text to a map I created. I want to move the text with the camera but first I need to get it to be much smaller... If you need more code just let me know :) Thanks in advance for the help :)
*** Why'd you run away? ****** Don't you like my... style***
Advertisement

why not using glScalef before calling glPrint ?
That did not even cross my mind to try... Duh moment... :) I'll work with that, Thanks!!
*** Why'd you run away? ****** Don't you like my... style***
Hi,

Did the glScalef work on your print function?

   glPushAttrib(GL_LIST_BIT);    glListBase(nFontList[2]);   glScalef (1.2, 1.2, 1.2);     glCallLists((int)str.length(), GL_UNSIGNED_BYTE, str.c_str());   glPopAttrib(); 



	HFONT	font;	HFONT	oldfont;	fontCount++;		nFontList[fontNumber] = glGenLists(128);	font = CreateFont(-12,												// Height Of Font						0,												// Width Of Font						0,												// Angle Of Escapement						0,												// Orientation Angle						FW_NORMAL,										// Font Weight						FALSE,											// Italic						FALSE,											// Underline						FALSE,											// Strikeout						ANSI_CHARSET,									// Character Set Identifier						OUT_TT_PRECIS,									// Output Precision						CLIP_DEFAULT_PRECIS,							// Clipping Precision						ANTIALIASED_QUALITY,							// Output Quality						FF_DONTCARE|DEFAULT_PITCH,						// Family And Pitch						fontName.c_str()//"Trebuchet MS"				// Font Name						);		oldfont = (HFONT)SelectObject(aDeviceContext, font);	wglUseFontBitmaps(aDeviceContext, 0, 127, nFontList[fontNumber]); // 0, 255, 20	SelectObject(aDeviceContext, oldfont);	DeleteObject(font);	



For me everything sizes except the text.
If you remember could you tell me how you got it to work ?
Thnx


We can forgive a man for making a useful thing as long as he does not admire it. The only excuse for making a useless thing is that one admires it intensely.-- ? --
In
[source lang=cpp]       if (outline == true) { // Comic Sans MS          MessageBox(NULL, "Outline", "Outline", MB_OK);          base = glGenLists(256);          font = CreateFont(-12,0,0,0,FW_BOLD,false,false,false,ANSI_CHARSET,                             OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,                             FF_DONTCARE | DEFAULT_PITCH,"Comic Sans MS");


you change the size of the font by changing the first number in the line:
font = CreateFont(-12,0,0,0,FW_BOLD,false,false,false,ANSI_CHARSET,
smaller numbers(for example -24) makes bigger text, while larger(for example 1) makes smaller.
Levi
True,

But i don't want to keep calling(for every size change)

wglUseFontBitmaps(HDC, 32, 96, base);



Doesn't scalef work ? (is there another way?)

Or

Should i load for every font and every size a list into memory ?
(Thats why i went looking for a different solution)

Thanks for the reply
We can forgive a man for making a useful thing as long as he does not admire it. The only excuse for making a useless thing is that one admires it intensely.-- ? --
Oh, ok, I understand. Couldn't you change the function so each time you call it, you pass a number to it, and have that number be the number that controls the size, so you can decide what size you want each time you call it?
Levi
I believe that when you call this functionm CreateFont()

 font = CreateFont(-12,0,0,0,FW_BOLD,false,false,false,ANSI_CHARSET,                             OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,                             FF_DONTCARE | DEFAULT_PITCH,"Comic Sans MS");



That you have to call this function(s):

	oldfont = (HFONT)SelectObject(aDeviceContext, font);	wglUseFontBitmaps(aDeviceContext, 0, 127, nFontList[fontNumber]); 	SelectObject(aDeviceContext, oldfont);	DeleteObject(font);	



And that produces the pain in the program when you constantly have to switch fonts.

Thats why i'am looking for a way to avoid calling those functions.

Again thanks for your time.
We can forgive a man for making a useful thing as long as he does not admire it. The only excuse for making a useless thing is that one admires it intensely.-- ? --
Ok, that was a dumb last post, sorry, i wasn't thinking.
I'll mess around with the scalef and try to figure out how to get it working.
Levi
Hi,
I'm stumped. : ) I did figure out, however, that glScalef works with NeHe's 3D font(outline font <a href="http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=14>lesson 14. Maybe you can use that??
Levi

This topic is closed to new replies.

Advertisement