BOOL Cgl::CreateMultiSample(HWND hwnd, BOOL bCreateZBuffer)/*by ZhouZhuo 2014.06.23 凹凸纹理 启动多采样抗锯齿 */{ m_hWnd =hwnd; //this->m_hWnd; m_hDC = ::GetDC(hwnd); DWORD depth_flag = PFD_DEPTH_DONTCARE; PIXELFORMATDESCRIPTOR pfd; if (bCreateZBuffer) depth_flag = 0; //PFD_MAIN_PLANE memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_SWAP_EXCHANGE | depth_flag; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = (BYTE)GetDeviceCaps(m_hDC, BITSPIXEL); pfd.cDepthBits = 24;//这里大多数机器只支持24 pfd.iLayerType = PFD_MAIN_PLANE; int nPixelFormat = ChoosePixelFormat(m_hDC, &pfd); if (nPixelFormat == 0) return false; nPixelFormat = 56 ;//采用作弊办法获得了16采样下的值, BOOL bResult = SetPixelFormat (m_hDC, nPixelFormat, &pfd); if (!bResult) return false; HGLRC tempContext = wglCreateContext(m_hDC); wglMakeCurrent(m_hDC, tempContext); GLenum err = glewInit(); if (GLEW_OK != err) { AfxMessageBox(_T("GLEW is not initialized!")); } int attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 1, WGL_CONTEXT_FLAGS_ARB, 0, 0 }; if(wglewIsSupported("WGL_ARB_create_context") == 1) { m_hRC = wglCreateContextAttribsARB(m_hDC,0, attribs); wglMakeCurrent(NULL,NULL); wglDeleteContext(tempContext); wglMakeCurrent(m_hDC, m_hRC); } else { //It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before) m_hRC = tempContext; } //Checking GL version const GLubyte *GLVersionString = glGetString(GL_VERSION); //Or better yet, use the GL3 way to get the version number int OpenGLVersion[2]; glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0]); glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1]); if (!m_hRC) return false; glewInit(); if (glewIsSupported("GL_VERSION_4_0")) printf("Ready for OpenGL 2.0\n"); else { printf("OpenGL 2.0 not supported\n"); //exit(1); } RECT r; ::GetClientRect(hwnd, &r); m_Width = r.right - r.left; m_Height = r.bottom - r.top; glViewport(0, 0, m_Width, m_Height); glDrawBuffer(GL_BACK); InitializeTexture(); wglMakeCurrent(NULL, NULL); m_bInitialized = TRUE; return TRUE; return true;}