Windows 95 mfc - Opengl Fonts

Windows 95 mfc - Opengl Fonts

Post by Dre » Thu, 29 Jan 1998 04:00:00



Hi,

I'm trying to get the word "Test" to show up in my scene.
Please tell me if you see any glaring errors in the font part of this
code.

Thank you,
Drew

int CTheView::OnCreate(LPCREATESTRUCT lpCreateStruct)
        if (CView::OnCreate(lpCreateStruct) == -1)
                return -1;

        /*other code*/

CDC* m_pDC = GetDC();
if(m_pDC)
{
        CFont  newfont;
        CFont* oldfont;
        BOOL   success;

        GLuint FontDisplayListBase = 1000;

        LOGFONT logfont;

        logfont.lfHeight            =28;
        logfont.lfWidth             =0;
        logfont.lfEscapement        =0;
             logfont.lfOrientation       =0;
        logfont.lfWeight            =FW_NORMAL;
        logfont.lfItalic            =FALSE;
        logfont.lfUnderline         =FALSE;
        logfont.lfStrikeOut         =FALSE;
        logfont.lfCharSet           =ANSI_CHARSET;
              logfont.lfOutPrecision      =OUT_DEFAULT_PRECIS;
        logfont.lfClipPrecision     =CLIP_DEFAULT_PRECIS;
        logfont.lfQuality           =DEFAULT_QUALITY;
             logfont.lfPitchAndFamily    =FF_DONTCARE|DEFAULT_PITCH;

        lstrcpy(logfont.lfFaceName,'\0');

             success = newfont.CreateFontIndirect(&logfont);
        oldfont = m_pDC->SelectObject(&newfont);

             success =
wglUseFontBitmaps(m_pDC->m_hDC,0,256,FontDisplayListBase);

        m_pDC->SelectObject(oldfont);

        ReleaseDC(m_pDC);

Quote:}

return 0;

Quote:}

void CTheView::OnDestroy()
{
        CView::OnDestroy();

        // TODO: Add your message handler code here
        glDeleteLists(1000,256);

Quote:}

void GLRenderScene(void)
{

        /*other code*/

{
        GLsizei size = strlen("Test");
        glListBase(100);
        ::glPushMatrix();
        ::glTranslatef(10.0f,10.0f,10.0f);
        glPushAttrib(GL_LIST_BIT);
        glCallLists(size,GL_UNSIGNED_BYTE,"Test");
              glPopAttrib();
        ::glPopMatrix();
        glListBase(0);

Quote:}

return;
Quote:}

 
 
 

Windows 95 mfc - Opengl Fonts

Post by Michael T. Renz » Sun, 08 Feb 1998 04:00:00


It looks like you're just copying a null character to the lfFaceName
member of logfont.
            lstrcpy(logfont.lfFaceName,'\0')
            ?
Have you tried, "Times New Roman" - or some other well known True Type
font?
Also,  why are you bothering with GL fonts when it's a lot easier to use
the device context
text output capabilities?  For example, in your OnDraw function, after
you've done your
GL rendering, use your logfont structure to create the font you want,
then use the OnDraw(CDC* pDC)
CDC ptr like so:

    pDC->TextOut("Test");

- Mike Renzi


> Hi,

> I'm trying to get the word "Test" to show up in my scene.
> Please tell me if you see any glaring errors in the font part of this
> code.

> Thank you,
> Drew

> int CTheView::OnCreate(LPCREATESTRUCT lpCreateStruct)
>         if (CView::OnCreate(lpCreateStruct) == -1)
>                 return -1;

>         /*other code*/

> CDC* m_pDC = GetDC();
> if(m_pDC)
> {
>         CFont  newfont;
>         CFont* oldfont;
>         BOOL   success;

>         GLuint FontDisplayListBase = 1000;

>         LOGFONT logfont;

>         logfont.lfHeight            =28;
>         logfont.lfWidth             =0;
>         logfont.lfEscapement        =0;
>              logfont.lfOrientation       =0;
>         logfont.lfWeight            =FW_NORMAL;
>         logfont.lfItalic            =FALSE;
>         logfont.lfUnderline         =FALSE;
>         logfont.lfStrikeOut         =FALSE;
>         logfont.lfCharSet           =ANSI_CHARSET;
>               logfont.lfOutPrecision      =OUT_DEFAULT_PRECIS;
>         logfont.lfClipPrecision     =CLIP_DEFAULT_PRECIS;
>         logfont.lfQuality           =DEFAULT_QUALITY;
>              logfont.lfPitchAndFamily    =FF_DONTCARE|DEFAULT_PITCH;

>         lstrcpy(logfont.lfFaceName,'\0');

>              success = newfont.CreateFontIndirect(&logfont);
>         oldfont = m_pDC->SelectObject(&newfont);

>              success =
> wglUseFontBitmaps(m_pDC->m_hDC,0,256,FontDisplayListBase);

>         m_pDC->SelectObject(oldfont);

>         ReleaseDC(m_pDC);
> }

> return 0;
> }

> void CTheView::OnDestroy()
> {
>         CView::OnDestroy();

>         // TODO: Add your message handler code here
>         glDeleteLists(1000,256);
> }

> void GLRenderScene(void)
> {

>         /*other code*/

> {
>         GLsizei size = strlen("Test");
>         glListBase(100);
>         ::glPushMatrix();
>         ::glTranslatef(10.0f,10.0f,10.0f);
>         glPushAttrib(GL_LIST_BIT);
>         glCallLists(size,GL_UNSIGNED_BYTE,"Test");
>               glPopAttrib();
>         ::glPopMatrix();
>         glListBase(0);
> }

> return;
> }