void CNeHeView::InitOpenGL()
{
 m_pClientDC = new CClientDC( this );
 ASSERT( m_pClientDC != NULL );
 ASSERT_VALID( m_pClientDC );
 
 if (! SetupPixelFormat())
  return;
 
 PIXELFORMATDESCRIPTOR pfd;
 
 int n=GetPixelFormat( m_pClientDC->GetSafeHdc());
 ::DescribePixelFormat( m_pClientDC->GetSafeHdc(), n, sizeof( pfd ),&pfd);
  hrc = wglCreateContext(m_pClientDC->GetSafeHdc());
 ASSERT(hrc);
 wglMakeCurrent( m_pClientDC->GetSafeHdc(),hrc); glClearColor(0.0f,1.0f,0.0f,1.0f);//设置背景颜色为黑色
 glOrtho(0,200,0,200,-1,1);
 
}   void CNeHeView::SetupPixelFormat()
{
 static PIXELFORMATDESCRIPTOR pfd = {
  sizeof( PIXELFORMATDESCRIPTOR ),// size of this pfd
   1,                              // version number
   PFD_DRAW_TO_WINDOW |            // support window
   PFD_SUPPORT_OPENGL |        // support OpenGL
   PFD_DOUBLEBUFFER,           // double buffered
   PFD_TYPE_RGBA,                  // RGBA type
   24,                             // 24-bit color depth
   0, 0, 0, 0, 0, 0,               // color bits ignored
   0,                              // no alpha buffer
   0,                              // shift bit ignored
   0,                              // no accumulation buffer
   0, 0, 0, 0,                     // accum bits ignored
   32,                             // 32-bit z-buffer
   0,                              // no stencil buffer
   0,                              // no auxiliary buffer
   PFD_MAIN_PLANE,                 // main layer
   0,                              // reserved
   0, 0, 0                         // layer masks ignored
 };
 
 int pixelformat = 0;
 
 ASSERT( m_pClientDC != NULL );
 if ( ( pixelformat = ChoosePixelFormat( m_pClientDC->GetSafeHdc(), & pfd ) ) == 0 )
 {
  AfxMessageBox( _T( "ChoosePixelFormat failed" ) );
  return FALSE;
 }
 
 if ( SetPixelFormat( m_pClientDC->GetSafeHdc(), pixelformat, & pfd ) == FALSE )
 {
  AfxMessageBox( _T( "SetPixelFormat failed" ) );
  return FALSE;
 }
 
 return TRUE;}  int CNeHeView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
 if (CView::OnCreate(lpCreateStruct) == -1)
  return -1; InitOpenGL();
 
 // TODO: Add your specialized creation code here 
 return 0;
}  void CNeHeView::OnDraw(CDC* pDC)
{
 CNeHeDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc); 
 wglMakeCurrent(m_pClientDC->GetSafeHdc(),hrc);
 MyDrawScene();
 SwapBuffers(m_pClientDC->GetSafeHdc());    wglMakeCurrent(m_pClientDC->GetSafeHdc(),NULL);
 // TODO: add draw code for native data here
 
}   void CNeHeView::MyDrawScene()
{  
 
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存  glLoadIdentity(); 
 glTranslatef(-1.5f,0.0f,-6.0f);   glBegin(GL_POLYGON); 
 
 glVertex3f(0,0,0); 
 glVertex3f(0,1,0); 
 glVertex3f(1,1,0); 
 glVertex3f(1,0,0);  glEnd(); 
 
 
  
 glFlush();}