欢迎来到天天文库
浏览记录
ID:39637753
大小:242.50 KB
页数:13页
时间:2019-07-08
《利用OpenGL添加AutoCAD中的平移与缩放功能》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、利用OpenGL添加AutoCAD中的平移与缩放功能1、添加openGL库,同过在dialog中添加picture控件来悬挂openGL视窗,悬挂方式如下:[cpp]viewplaincopyBOOLCDemoSectionDlg::InitPic()//初始化openGL视窗{CWnd*wnd=GetDlgItem(IDC_RENDER);//IDC_RENDER为picture控件IDhrenderDC=::GetDC(wnd->m_hWnd);//hrenderDC为类成员变量HDChrenderDC;//设备
2、上下文if(SetWindowPixelFormat(hrenderDC)==FALSE)return0;if(CreateViewGLContext(hrenderDC)==FALSE)return0;CRectrc;wnd->GetClientRect(&rc);//rc为控件的大小。glViewport(0,0,(GLsizei)(rc.Width()),(GLsizei)(rc.Height()));glMatrixMode(GL_PROJECTION);glEnableClientState(GL_VERT
3、EX_ARRAY);glEnableClientState(GL_TEXTURE_COORD_ARRAY);returnTRUE;}BOOLCDemoSectionDlg::CreateViewGLContext(HDChDC)//创建viewGLContext{hrenderRC=wglCreateContext(hDC);//hrenderRC为类成员变量HGLRChrenderRC;//渲染上下文if(hrenderRC==NULL)returnFALSE;if(wglMakeCurrent(hDC,hrend
4、erRC)==FALSE)returnFALSE;returnTRUE;}BOOLCDemoSectionDlg::SetWindowPixelFormat(HDChDC)//设定像素格式{PIXELFORMATDESCRIPTORpixelDesc;pixelDesc.nSize=sizeof(PIXELFORMATDESCRIPTOR);pixelDesc.nVersion=1;pixelDesc.dwFlags=PFD_DRAW_TO_WINDOW
5、PFD_SUPPORT_OPENGL
6、PFD_DOUBLEBU
7、FFER
8、PFD_TYPE_RGBA;pixelDesc.iPixelType=PFD_TYPE_RGBA;pixelDesc.cColorBits=32;pixelDesc.cRedBits=0;pixelDesc.cRedShift=0;pixelDesc.cGreenBits=0;pixelDesc.cGreenShift=0;pixelDesc.cBlueBits=0;pixelDesc.cBlueShift=0;pixelDesc.cAlphaBits=0;pixelDesc.cAlphaShift=0;p
9、ixelDesc.cAccumBits=0;pixelDesc.cAccumRedBits=0;pixelDesc.cAccumGreenBits=0;pixelDesc.cAccumBlueBits=0;pixelDesc.cAccumAlphaBits=0;pixelDesc.cDepthBits=0;pixelDesc.cStencilBits=1;pixelDesc.cAuxBuffers=0;pixelDesc.iLayerType=PFD_MAIN_PLANE;pixelDesc.bReserved=0;
10、pixelDesc.dwLayerMask=0;pixelDesc.dwVisibleMask=0;pixelDesc.dwDamageMask=0;PixelFormat=ChoosePixelFormat(hDC,&pixelDesc);if(PixelFormat==0)//Choosedefault{PixelFormat=1;if(DescribePixelFormat(hDC,PixelFormat,sizeof(PIXELFORMATDESCRIPTOR),&pixelDesc)==0){returnF
11、ALSE;}}if(SetPixelFormat(hDC,PixelFormat,&pixelDesc)==FALSE){returnFALSE;}returnTRUE;}2、在视窗上画图,函数如下:[cpp]viewplaincopyvoidCDemoSectionDlg::RenderScene(doublex,doubley){glCle
此文档下载收益归作者所有