建立一个SDI 的MFC工程,然后按freeglut 在mfc 下的编译_leon_zeng0的博客-CSDN博客
一文设置好include lib 路径
在view 中建立这2个函数:
// Standard OpenGL Init Stuff
BOOL CmfcOpenglDemoView::SetupPixelFormat()
{
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, // accumulation bits ignored
16, // 16-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 m_nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
if (m_nPixelFormat == 0)
return FALSE;
return ::SetPixelFormat(m_pDC->GetSafeHdc(), m_nPixelFormat, &pfd);
}
BOOL CmfcOpenglDemoView::InitOpenGL()
{
TRACE(L"InitOpenGL()\n");
//Get a DC for the Client Area
m_pDC = new CClientDC(this);
//Failure to Get DC
if (m_pDC == NULL)
return FALSE;
if (!SetupPixelFormat())
return FALSE;
//Create Rendering Context
m_hRC = ::wglCreateContext(m_pDC->GetSafeHdc());
//Failure to Create Rendering Context
if (m_hRC == 0)
return FALSE;
//Make the RC Current
if (::wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC) == FALSE)
return FALSE;
/
本文介绍了如何在MFC(MicrosoftFoundationClasses)的SDI(SingleDocumentInterface)应用中使用FreeGlut进行OpenGL的编译设置,包括设置像素格式、创建渲染上下文和视图函数,以及实现基本的OpenGL绘图功能。
最低0.47元/天 解锁文章
1766

被折叠的 条评论
为什么被折叠?



