OPENGLAppWizard下载链接
放C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Template\下,具体目录根据你自己装的VC位置。
1、新建工程,选择OPENGLAppWizard。
2.选择单文档。
3.添加Windows消息处理函数WM_CREATE、WM_DESTROY、WM_SIZE消息处理函数,点击EditExisting进入编辑界面。
编辑消息处理函数,只需增加三行代码。
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here InitGL();//你需要自己添加这行代码 return 0; } void CMyView::OnDestroy() { CView::OnDestroy(); // TODO: Add your message handler code here DestroyGL();//你需要自己添加这行代码 } void CMyView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); // TODO: Add your message handler code here ReSizeGL(nType, cx, cy);//你需要自己添加这行代码 }
点击运行即可看到一个彩色正方形,具体画图形的函数在DrawGLScene()里,
把里面的函数全部删掉,改为自己的绘图函数即可。
//绘图函数实现 void CMyView::DrawGLScene() //画图函数 { //示例 下面添上绘图代码 glTranslatef(0.0f,0.0f,-3.0f); glRotatef(90.0f,1.0f,0.0f,0.0f); //GL_QUADS每四个连续的顶点定义一个四边形 glBegin(GL_QUADS); //立方体顶面 glColor3f(1.0f,0.0f,1.0f); glVertex3f(-0.5,0.5f,0.5f); //1点 glColor3f(1.0f,1.0f,1.0f); glVertex3f(0.5f,0.5f,0.5f); //3点 glColor3f(0.0f,1.0f,1.0f); glVertex3f(0.5f,0.5f,-0.5f); //5点 glColor3f(0.0f,0.0f,1.0f); glVertex3f(-0.5f,0.5f,-0.5f); //7点 glEnd(); }