Text does not always display

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;
LOGFONT lf;
::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.

I think I’ve narrowed this down a bit. I have two viewports in my 2D window. I draw test using the following code in each viewport:

strText = “Some Great Text”;
glRasterPos2d( Xcoord,Ycoord);//position the text
glListBase( FONT_LISTBASEVARIABLE );
glCallLists( strText.GetLength(), GL_UNSIGNED_BYTE, strText );//draw the text in the window.

The text ALWAYS shows up in the first viewport, WITHOUT FAIL. However, the text sometimes shows up in the 2nd viewport, sometimes it doesn’t. There doesn’t seem to be any rhyme or reason why it doesn’t show up sometimes in this second viewport. It’s as if the 2nd viewport doesn’t know what font to use, so it draws nothing.

Presumably somewhere you are calling glGenLists() and wglUseFontBitmaps() to create the display lists for the font? I have had situations where wglUseFontBitmaps() failed without any reason and had to call it again for it to work e.g.:
if (!wglUseFontBitmaps(m_hDC, 0, ms_iListSize, m_uiFontList))
wglUseFontBitmaps(m_hDC, 0, ms_iListSize, m_uiFontList);

If you have two views are the model view and projection matrices and the viewport of the second view set up correctly?