I have a 2D openGL window in my C++ MFC application. I’m displaying some text in the window. The problem is that sometimes the text simply doesn’t show up. The issue is related to the system font, I believe. The reason I believe this is the following: Just before I call the function to write the text, if I add a line to fetch the system font, everything works great. MY TEXT DISPLAYS in the window, EVERYTIME, without fail. Here is the code that makes the text appear correctly:
// get current OpenGL font description
CFont* pFontOpenGL = NULL;
::GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
//then write the text in the openGL window
strText = “Some Great Text”;
glRasterPos2d( Xcoord,Ycoord);//position the text in the window, at location (Xcoord, Ycoord)
glListBase( FONT_LISTBASEVARIABLE );
glCallLists( strText.GetLength(), GL_UNSIGNED_BYTE, strText );//draw the text in the window.
Again, as long as I have the call to ::GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf) just before I draw the text, my text will display properly (ie, the text is visible). But if I comment out that call, the text sometimes doesn’t appear. The strange this is that I’m not doing anything with the system font once I retrieve it. I’m simply RETRIEVING IT. I really don’t want to have that call in there, because it’s a hack, and might cause other unforseen issues.
Any light that can be shed on what’s going on here would be greatly appreciated.