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

PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 
24,
0, 0, 0, 0, 0, 0,
0, 0, 0,
0, 0, 0, 0,
32,
0, 
0, 
PFD_MAIN_PLANE,
0,
0, 0, 0
}; m_hDC = GetDC()->GetSafeHdc();
int nPixelFormat = ::ChoosePixelFormat(m_hDC, &pfd);
::SetPixelFormat(m_hDC, nPixelFormat, &pfd);
m_hRC = ::wglCreateContext(m_hDC);
::wglMakeCurrent(m_hDC, m_hRC);

return 0;
}void CTestexeView::OnDestroy() 
{
CView::OnDestroy();

::wglMakeCurrent(NULL, NULL);
::wglDeleteContext(m_hRC);
}BOOL CTestexeView::OnEraseBkgnd(CDC* pDC) 
{
return true;
}void CTestexeView::OnSize(UINT nType, int cx, int cy) 
{
CView::OnSize(nType, cx, cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30, 1, -3, 3);
glMatrixMode(GL_MODELVIEW);
glViewport(0, 0, cx, cy);
glShadeModel(GL_FLAT);
}BOOL CTestexeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs
cs.style |= (WS_CLIPSIBLINGS|WS_CLIPCHILDREN);
return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CTestexeView drawingvoid CTestexeView::OnDraw(CDC* pDC)
{
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(5, 5, 5, 0, 0, 0, 0, 0, 1);
glColor3f(1, 0, 0);
auxWireCylinder(1, 1);
auxWireSphere(1);
SwapBuffers(m_hDC);
}

解决方案 »

  1.   

    m_hDC = GetDC()->GetSafeHdc();
    申请DC后需要释放。
      

  2.   

    CTestexeView::OnCreate()
    {       m_pDC = 
    }
    加了
      

  3.   

    CTestexeView::OnCreate()
    {       ......
           m_pDC = GetDC();
           m_hDC = m_pDC->GetSafeDC();
           ......
    }CTestexeView::OnDestroy()
    {
           ......
           if(m_pDC) m_pDC->ReleaseDC();
          ......
    }还是提示内存泄露
    Detected memory leaks!
    Dumping objects ->
    {128} normal block at 0x048E3FA0, 16 bytes long.
     Data: <             ?  > 01 00 00 00 00 00 00 00 02 00 00 00 E0 3F 8E 04 
    {127} normal block at 0x048E3FE0, 16 bytes long.
     Data: <       ?       ?> 00 00 00 00 00 00 F0 3F 00 00 00 00 00 00 F0 3F 
    Object dump complete.
    是不是我的opengl开发包有问题?
      

  4.   

    你们谁帮我做个简单点的opengl程序(其中调用auxWireSphere())
      

  5.   

    应该放到析构函数中释放。而不是OnDestroy中。
    ::wglDeleteContext(m_hRC);这句放到析构函数中调用