OpenGL Programming for Windows MFC


14. 2D Japanese Text


14.1 OnCreateを以下のように変更

void CXXXView::OnCreate() 
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;
    m_pDC = new CClientDC(this) ;             // Get device context
    SetDCPixelFormat(m_pDC->m_hDC) ;          // Set OpenGL pixel format
    m_GLRC = wglCreateContext (m_pDC->m_hDC); // Create rendering context
    wglMakeCurrent (m_pDC->m_hDC, m_GLRC);    // Current context set
    InitGL() ;                                // Initalize OpenGL

    MatGL() ;                                  // Material setup

    m_pRGBImage = auxDIBImageLoad("tiger.bmp"); // Tiger BMP

    TexGL(m_pRGBImage->sizeX, m_pRGBImage->sizeY, m_pRGBImage->data) ;

    Light1GL() ;                               // Light1 Setup

    FogGL() ;                                  // Fog Setup

    wglUseFontBitmaps(m_pDC->m_hDC, 0, 256, 2000) ;

    makeStringFont("日本語ゴジラらっきょの酢漬け(Japanese Text)");

    return 0;
}
OnCreate is changed as mentioned above.


14.2 DrawGLを以下のように変更

GLint DrawGL(GLfloat m_curquat[4])
{
    GLfloat m[4][4] ;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

    glMatrixMode(GL_MODELVIEW) ;
    glLoadIdentity() ;
    glTranslated(0.0, 0.0, -3.0) ;

    glPushMatrix() ;

    build_rotmatrix(m , m_curquat) ;
    glMultMatrixf(&m[0][0]) ;

    glCallList(1) ;    // Object material

    glEnable(GL_TEXTURE_2D ) ;
    glCallList(2) ;    // Texture 

    glCallList(3) ;    // Light1 position(rotate with object)

    glEnable(GL_NORMALIZE) ;
    glEnable(GL_AUTO_NORMAL) ;
        auxSolidTeapot(1.0) ;
    glDisable(GL_AUTO_NORMAL) ;
    glDisable(GL_NORMALIZE) ;
    glDisable(GL_TEXTURE_2D ) ;

    glPopMatrix() ;

    glPushAttrib(GL_ALL_ATTRIB_BITS) ;
        glDisable(GL_FOG) ;
        glEnable(GL_COLOR_MATERIAL) ;
        glDisable(GL_LIGHTING) ;
        glColor3d(1.0f, .0f, .0f) ;
        glListBase(2000) ;
        glRasterPos3d(-2.5, 1., 0) ;
        glCallLists(21, GL_UNSIGNED_BYTE, "OpenGL for WindowsMFC") ;

        glRasterPos3d(-2.5, 1.30, 0.0);
        printString();

    glPopAttrib() ;

    return(0) ;
}

14.3 JText.c

JText.c download


14.4 Build and Execute



prev