PDA

View Full Version : Help!!! OpenGl and CreateDIBSection



gardras
01-21-2002, 09:31 AM
what's wrong with the code:


hdc = GetDC(hWnd); // creating bitmaps in memory with size of client area

// GlPlane
GlPlane.hdcMem = CreateCompatibleDC(hdc);

BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biWidth = cxClient;
BitmapInfo.bmiHeader.biHeight = cyClient;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 24;
BitmapInfo.bmiHeader.biCompression = BI_RGB;
BitmapInfo.bmiHeader.biSizeImage = 0;
BitmapInfo.bmiHeader.biClrUsed = 0;
BitmapInfo.bmiHeader.biClrImportant = 0;
BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
BitmapInfo.bmiHeader.biYPelsPerMeter = 0;


GlPlane.hBitmap = CreateDIBSection(hdc,&BitmapInfo,DIB_RGB_COLORS,&pBits,NULL,0);
SelectObject(GlPlane.hdcMem,GlPlane.hBitmap);

memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR)) ;
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;

iPixelFormat = ChoosePixelFormat(GlPlane.hdcMem,&pfd);
SetPixelFormat(GlPlane.hdcMem,iPixelFormat,&pfd);

hrc = wglCreateContext(GlPlane.hdcMem);
wglMakeCurrent(GlPlane.hdcMem,hrc);


glViewport(0, 0, cxClient, cyClient);
glLoadIdentity();
glOrtho(0.0f, cxClient, 0.0f, cyClient, 1.0f, -1.0f);

glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(100.0f, 100.0f, 200.0f, 200.0f);
glFlush();
GdiFlush();
BitBlt(hdc,0,0,cxClient,cyClient,GlPlane.hdcMem,0, 0,SRCCOPY);

ReleaseDC(hWnd,hdc);


i got rendering context but it doesn't want to draw on the bitmap
or maybe the bitmap has size of 0????
help needed urgently

opla
01-21-2002, 09:48 AM
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
try pfd.cColorBits = 32;

mmcoder
01-21-2002, 09:51 AM
This is a guess, but is it possible that there's some 24/32bit incompatability happening? try making a 32bit color bitmap

gardras
01-21-2002, 10:02 AM
i tried it and nothing

i think it's something its bitmap problem because GDI FillRect function doesn't work also

dpsv
01-21-2002, 10:03 AM
Hi,
I do the following and it works

GlMemDC = CreateCompatibleDc(NULL);
memBitmap = CreateDIBSection(0,BitmapInfo,DIB_RGB_COLORS,&pBits,NULL,0);
OldmemBitmap = SelectObject(GlMemDc, memBitmap);

DPS

cherif
01-21-2002, 01:42 PM
try adding a glMatrixMode( GL_PROJECTION) after glViewport and before glLoadIdentity.

Also, if I understand correctly, the values in glOrtho should be the user data (which you specify when drawing), not the Window client coordinates, unless you want them to be the same. For example, glViewport should have the dimensions of the window client area (in client coordinates), and the glOrtho should have the dimensions of the object to draw in user coordinates (e.g. 10000, 20000, -20000, ...)

I hope this helps.