View Full Version : MFC and Nehe fonts don't work together
02-11-2001, 07:58 AM
I am using mfc to get a GUI for a level editor. I needed to add a text routine so the OpenGL window can display some informatio about position etc. without having to set up another window or dialog box. So I used NeHe's lesson 14 on Outline fonts and added the code to the CDoc class with any varibles initiated in the classes header. The only alteration made was that the BuildFont(GLvoid) was changed to BuildFont(HDC hDC)to get the device context used in the wglUseFontOutlines() command in the function. The program compiles and links fine and also runs as normal. The problem is that the text I specify isn't displayed. I loadded the identity matrix, translated back along the z-axis -10 units and used the glPrint function that was created, but nothing displays. I also removed my drawing stuff and added the stuff from the tutorial(that does a similar thing as mine) and still no text displays. The color is set white with the clear color black so that isn't it.
Any Suggestions why it shouldn't work (maybe its to do with the hDC - I don't undertand this, but there is no errors reported when compiled.
02-13-2001, 08:25 AM
I just remembered I havn't called BuildFont, so I added this to the CView OnCreate Function AND IT STILL DOESN'T WORK !!!
Has any one have any example of using text in opengl using MFC, any links?
02-13-2001, 09:09 AM
I had similar problems with the NeHe tutorial. The following worked for me...i think its Nate Robins but not sure anymore.
font.CreateFont( -12, //height of font
0, //width of font
0, //angle of escapement
0, //orientation angle
FW_NORMAL, //font weight
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
CFont* pOldFont = m_pDC->SelectObject(&font);
m_textList = glGenLists(256);
wglUseFontBitmaps(m_pDC->GetSafeHdc(), 1, 255, m_textList);
Then initialize your device context somewhere
m_pDC = new CClientDC(this); //dc created for drawing text- type CDC*
if(m_pDC == NULL)
MessageBox("Error Obtaining DC");
And in your render function:
glCallLists(9, GL_UNSIGNED_BYTE ,"your text");
[This message has been edited by link19 (edited 02-13-2001).]
02-14-2001, 08:23 AM
Thanks alot link19, However it still doesn't work so I guess the problem my app. So I created a new project and setup the usual opgl init. stuff (PFD etc.) I then put in the text functions and it worked? The only differnece between the new project and my app is that in my app I do all rendering in the CDoc class while in the new project the rendering was done in the CView class. So I changed my app to render some text in the CView class and not the CDoc and again NO TEXT IS SEEN.
I'm confused!!!!!!!!!! http://www.opengl.org/discussion_boards/ubb/confused.gif. I need a window to smash http://www.opengl.org/discussion_boards/ubb/mad.gif.
PLEASE SOMEONE HELP. If some one could e-mail me an mfc project using some text I would be grateful, or if you want me to e-mail the source code http://www.opengl.org/discussion_boards/ubb/smile.gif
Oh yes they do. The problem your having is definely with your application. I have it working in a code that I can't send to you. If I have a chance this weekend I'll gut the code and send it to you if your still interested and can wait that long. I remember having some diffculties that were resolved by changing the calling order in the code. I'm also trying to put a OpenGL MFC tutorial website (heavy on the MFC side) together. I need a host. Any thoughts or ideas?
02-16-2001, 08:33 AM
jp, I would be interested in both the code and the tutorials on mfc. I'm making a simple level editor using mfc for the gui and its taking me some time to understand , I now know the basics but trying to do anything new is impossible, even using the help files.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.