OpenGL Programming for Windows MFC
13. 2D Text
13.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) ;
return 0;
}
OnCreate is changed as mentioned above.
13.2 OnDestroyを以下のように変更
void CXXXView::OnDestroy()
{
CView::OnDestroy();
glDeleteLists(2000,256) ;
free( m_pRGBImage->data) ; // free DIB image area
free( m_pRGBImage );
wglMakeCurrent (NULL, NULL); // free current context
wglDeleteContext (m_GLRC); // Delete rendering context
delete m_pDC ; // Release device context
}
OnDestroy is changed as mentioned above.
13.3 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") ;
glPopAttrib() ;
return(0) ;
}
prev next