画一个旋转的立体1.pptVIP

  • 11
  • 0
  • 约 37页
  • 2016-12-03 发布于河南
  • 举报
画一个旋转的立体1

Assignment #2 Part I: drawing a color cube Part II: rotating a color cube 创建一个MFC AppWizard(exe) 工程,名为ColorCube 选择单文档,其他的默认即可。 Project Settings (1/2) Project Settings (2/2) Opengl32.lib glu32.lib glut.lib glut32.lib Include Header Files Member Variables and Functions CDC *m_pDC; HGLRC m_hRC; BOOL SetupPixelFormat(PIXELFORMATDESCRIPTOR *pPFD=0); void DrawScene(); Class Wizard (1/2) Class Wizard (2/2) OnCreate( ) (1/2) OnCreate( ) (2/2) int CColorCubeView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here m_pDC = new CClientDC(this); // get device context if( m_pDC == NULL ) { ::AfxMessageBox( fail to get device context ); return FALSE; } if( !SetupPixelFormat() ) // setup pixel format { ::AfxMessageBox( SetupPixelFormat failed ); return FALSE; } // get rendering context if( ( m_hRC = wglCreateContext(m_pDC-GetSafeHdc()) ) == 0 ) { ::AfxMessageBox( wglCreateContext failed ); return FALSE; } // make current rendering context if( wglMakeCurrent(m_pDC-GetSafeHdc(), m_hRC) == FALSE ) { ::AfxMessageBox( wglMakeCurrent failed ); return FALSE; } return 0; } 编此程序遇到得问题: 在得到RC时,注意语句是 先赋值给m_hRC然后再判断其是否为NULL,否则wglCreateContext failed 错误。 OnDestory( ) if(wglMakeCurrent(0,0) == FALSE)//delete current context ::AfxMessageBox(wglMakeCurrent failed); if(m_hRC (wglDeleteContext(m_hRC) == FALSE)) ::AfxMessageBox(wglDelelteContext failed); if(m_pDC) delete m_pDC; OnEraseBkgnd( ), OnSize( ) glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0,0, cx, cy); glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0); PreCreateWindow( ), OnDraw( ) cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN; SetupPixelFormat( ) (1/2) SetupPixelFormat( ) (2/2) BOOL CColorCubeView::SetupPixelFormat(PIXELFORMATDESCRIPTOR* pPFD) { PIXELFORMATDESCRIPTOR pfd = { sizeof( PIXELFORMATDESCRIPTOR ), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, PFD_TYPE_RGBA, 24,

文档评论(0)

1亿VIP精品文档

相关文档