专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »C 教程 » opengl:OpenGL多视图的实现 »正文

opengl:OpenGL多视图的实现

来源: 发布时间:星期四, 2009年2月12日 浏览:216次 评论:0


实现效果图

\" width=630>




  关键技术实现介绍:

  、OpenGL多视图实现

  平常我们大部分都是建立OpenGL设备上下文但在本由于要实现 3维实体多视图观察功能因此需要建立多OpenGL设备上下文并在需要时候进行切换

  同OpenGL我们在每个视图类中都定义了每个视图所对应设备描述上下文并在视图创建时候建立了这个设备描述上下文

//add in the header file of view
public:
CClientDC* m_pDC;
HGLRC m_hRC;
//add in the init function of view
m_hRC = wglCreateContext(m_pDC->GetSafeHdc);


  接着在某个视图需要更新时候(般在每个视图OnDraw中)将这个视图设备上下文设为OpenGL当前渲染上下文(OpenGL Rendering context)

//add in the _disibledevent=> //add in the header file of child view
//view ID, it will be assigned by parentframe when this program begin
//[childviewA id = 1; childviewB id = 2]
m_ViewID


  然后在运行的初浮动窗体创建的后对每个浮动窗体所包含子视图类型进行设置

//add in the _disibledevent=> (pdoc)
 {
  POSITION pos = pdoc->GetFirstViewPosition;
  CView* pview;
   tempid = 1;
  while (pos != NULL)
  {
   pview = pdoc->GetNextView(pos);
    (pview->IsKindOf(RUNTIME_CLASS(CChildOGLView)))
   {
    CChildOGLView* pchildview = (CChildOGLView*)pview;
    pchildview->m_ViewID = tempid;
    tempid 1;
   }
  }
 }
}


  我们看到这里需要从文档类中检索出所有子视图(CChildOGLView)因此在子视图创建时候需要把自己加入到文档中

//add in the _disibledevent=> (pdoc != NULL)
 {
  pdoc->AddView(this);
 }
}


  至此关键功能已经实现在主视图和子视图绘制部分便可以通过判断当前视图类型进行区别内容绘制

//in the DrawScene function of view
//To get the current view type
ViewType currentviewtype;
CMainFrame* pframe = (CMainFrame*)GetParentFrame;
currentviewtype = pframe->m_ViewArrange.m_MainViewType;
glViewport(0, 0, m_oldRect.right, m_oldRect.bottom);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
CEdit3DMDoc* pdoc = GetDocument;
(pdoc != NULL)
{
 pdoc->m_3DMani.SetProjection(currentviewtype, 0);
 pdoc->m_3DMani.DrawBound(currentviewtype);
}
glFinish;
SwapBuffers(wglGetCurrentDC);

//in the DrawScene function of child view
ViewType currentviewtype;
CMainFrame* pframe = (CMainFrame*)AfxGetMainWnd;
(m_ViewID 1)
{
 currentviewtype = pframe->m_ViewArrange.m_ChildViewAType;
}
(m_ViewID 2)
{
 currentviewtype = pframe->m_ViewArrange.m_ChildViewBType;
}
glViewport(0, 0, m_oldRect.right, m_oldRect.bottom);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

CEdit3DMDoc* pdoc = GetDocument;
(pdoc != NULL)
{
 pdoc->m_3DMani.SetProjection(currentviewtype, 0);
 pdoc->m_3DMani.DrawBound(currentviewtype);
}


glFinish;
SwapBuffers(wglGetCurrentDC);


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: