您的位置:首页 >> 编程开发 >> Visual C++ >> ATL/COM/ActiveX >> 正文
ATL/COM/ActiveX RSS
 

如何VC下用ATL做一个OpenGL的(COM)控件

http://www.rdxx.com 07年05月17日 00:00 我要投稿

关键词: OpenGL , ATL , VC , 控件 , COM , Open

    目的:由于在写OpenGL程序的时候这些东西每次都要写一遍,而且特别繁琐!为了刚步入OpenGL人提供一个界面控件,让他们较早的看到自己写的OpenGL程序的效果!让他们觉得OpenGL的神奇! 

    作者:王卫星(wangweixing2000) 

    1, 新建一个ATL空项目(项目名OpenGL_ATL) 

    2, 添加一个ATL对象(MyControl)(VC6下为Full Control,VC7下为ATL控件)必须选中Support Connection Points为了添加事件。 

    3, 在对象的.H头文件中添加:

 #include <gl/gl.h>
#include <gl/glu.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib") 

    4, 在接口实现类添加一个OpenGL 的RC(rendering context)成员变量:

HGLRC m_hRC; 
    5, 添加一个设置OpenGL像素格式(接口实现类的)成员函数:

// Set OpenGL pixel format for given DC

BOOL MyControl::SetupPixelFormat(HDC hdc)

{

  static PIXELFORMATDESCRIPTOR pfd =

  {

    sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd

      1,              // version number

      PFD_DRAW_TO_WINDOW |     // support window

      PFD_SUPPORT_OPENGL |     // support OpenGL

      PFD_DOUBLEBUFFER,      // double buffered

      PFD_TYPE_RGBA,        // RGBA type

      24,             // 24-bit color depth

      0, 0, 0, 0, 0, 0,      // color bits ignored

      0,              // no alpha buffer      

0,              // shift bit ignored

      0,              // no accumulation buffer

      0, 0, 0, 0,         // accum bits ignored

      32,             // 32-bit z-buffer

      0,              // no stencil buffer

      0,              // no auxiliary buffer

      PFD_MAIN_PLANE,       // main layer

      0,              // reserved

      0, 0, 0           // layer masks ignored

  };

  int pixelformat;



  if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)

  {

    ATLASSERT(FALSE);

    return FALSE;

  }



  if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE)

  {

    ATLASSERT(FALSE);

    return FALSE;

  }



  return TRUE;

共2页  1 2

 
 
标签: OpenGL , ATL , VC , 控件 , COM , Open 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站