1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| //-------------------------------------------------------------------------------
void setGDI(HGLRC& glMemRC, HDC& glMemDC){
glMemDC=CreateCompatibleDC(NULL);
UINT * ptPixels;
HBITMAP memBitmap = createDeviceIndependantBitmap(glMemDC, ptPixels);
if(memBitmap==0) {
cerr<<"CreateDeviceIndependantBitmap error"<<endl;
return;}
setPixelFormat(glMemDC);
glMemRC=wglCreateContext(glMemDC);
SelectObject(glMemDC, memBitmap);
wglMakeCurrent(glMemDC,glMemRC); }
//-------------------------------------------------------------------------------
HBITMAP createDeviceIndependantBitmap(HDC& deviceContext, UINT * ptPixels){
BITMAPINFO RGB8BitsBITMAPINFO;
ZeroMemory(&RGB8BitsBITMAPINFO,sizeof(BITMAPINFO));
RGB8BitsBITMAPINFO.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
RGB8BitsBITMAPINFO.bmiHeader.biWidth=1000;
RGB8BitsBITMAPINFO.bmiHeader.biHeight=1000;
RGB8BitsBITMAPINFO.bmiHeader.biPlanes=1;
RGB8BitsBITMAPINFO.bmiHeader.biBitCount=8;
HBITMAP memBitmap = CreateDIBSection(deviceContext,
(BITMAPINFO *)&RGB8BitsBITMAPINFO,
DIB_RGB_COLORS,
(void **)&ptPixels,
NULL, 0);
return memBitmap;}
//-------------------------------------------------------------------------------
void setPixelFormat(HDC& deviceContext){
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_BITMAP | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_SUPPORT_GDI, // double buffered
PFD_TYPE_RGBA, // RGBA type
8, // 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
0, // 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 pixelFormatIndex = ChoosePixelFormat(deviceContext, &pfd);
if(pixelFormatIndex==0)
cerr<<"ChoosePixelFormatt error"<<endl;
bool r = SetPixelFormat(deviceContext,pixelFormatIndex,&pfd);
if(r!=TRUE) {cerr<<"setPixelFormat error"<<endl;}}
//-------------------------------------------------------------------------------
void readHBITMAP(HDC& deviceContext, mon_image& im) {
RGBQUAD * pColors = (RGBQUAD *)malloc(1000000*sizeof(RGBQUAD *));
int success = GetDIBColorTable(deviceContext, 0, 1000000, pColors);
if(success ==0){
cerr << "readHBITMAP error"<<endl;}
else{
for(int i=0; i<1000; i++)
for(int j=0; j<1000; j++){
im.set_rouge(i, j) = pColors[i*1000+j].rgbRed;
im.set_bleu(i, j) = pColors[i*1000+j].rgbBlue;
im.set_vert(i, j) = pColors[i*1000+j].rgbGreen;}}}
//------------------------------------------------------------------------------- |
Partager