PDA

View Full Version : Problems with wglCreateContext and wglMakeCurrent



jeselviz
05-17-2001, 05:14 AM
This my code, but it doesn´t work. The obtained bmp file is empty. Someone can help me?

CDC dc;
dc.CreateCompatibleDC(NULL);
BITMAPINFO info;
HBITMAP bitmap;
//GLubyte *bits;
void *bits;

memset( &info, 0, sizeof( info ) );
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = 800;
info.bmiHeader.biHeight = 600;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = 24;
info.bmiHeader.biCompression = BI_RGB;

bitmap = CreateDIBSection(dc, &info, DIB_RGB_COLORS, &bits, NULL, 0);
SelectObject(dc, bitmap);

PIXELFORMATDESCRIPTOR pfd;
int pf;

memset(&pfd, 0, sizeof(pfd));

pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cRedBits = 8;
pfd.cGreenBits = 8;
pfd.cBlueBits = 8;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;

pf = ChoosePixelFormat (dc, &pfd);
SetPixelFormat (dc, pf, &pfd);

m_hrc = wglCreateContext (dc);
wglMakeCurrent (dc, m_hrc);
OnDraw(&dc);

memset( &bf, 0, sizeof( bf ) );
memset( &bi, 0, sizeof( bi ) );

bf.bfType = 'MB';
bf.bfSize = sizeof(bf)+sizeof(bi)+800*600*3;
bf.bfOffBits = sizeof(bf)+sizeof(bi);
bi.biSize = sizeof(bi);
bi.biWidth = 800;
bi.biHeight = 600;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biSizeImage = 800*600*3;

fwrite( &bf, sizeof(bf), 1, file );
fwrite( &bi, sizeof(bi), 1, file );
fwrite( bits, sizeof(unsigned char), 800*600*3, file );

fclose( file );