关于OpenGL在内存DC绘制的问题
先上代码:
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = 150;
bmi.bmiHeader.biHeight = 150;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
HBITMAP hDIB = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, (DWORD)0);
HDC hMem = CreateCompatibleDC(NULL);
SelectObject(hMem, hDIB);
BITMAP bm;
::GetObject(hDIB, sizeof(bm), &bm);
unsigned int* m_pBitmap = static_cast<unsigned int*>(bm.bmBits);
memset(m_pBitmap,255,150*150*4);
PIXELFORMATDESCRIPTOR pfd;
/* set the pixel format for the DC */
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP |PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat(hMem, &pfd);
SetPixelFormat(hMem, iFormat, &pfd);
/* create and enable the render context (RC) */
HGLRC hRC = wglCreateContext(hMem);
if (hRC == 0) std::cout<<"OpenGL resource context creation failed";
wglMakeCurrent(hMem, hRC);
glClearColor( 1.0f, 0.0f, 0.0f, 1.0f );
glClear(GL_COLOR_BUFFER_BIT);
glFinish();