PDA

View Full Version : render on a bitmap in Borland C++ Builder



Lelik
07-29-2004, 03:53 AM
I'm trying to render on a bitmap in BC++ Builder 5.0. I read in MSDN (which, unfortunately, deals with M$ stuff, not Borland) that the number of bits per pixels for the bitmap should be equal to that in the PIXELFORMATDESCRIPTOR. So here's the code:


prBM = new Graphics::TBitmap;
prBM->PixelFormat = pf24bit;
hdc = prBM->Canvas->Handle; // is this the right handle to use here?

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};

PixelFormat = ChoosePixelFormat(hdc, &pfd);
if (!SetPixelFormat(hdc, PixelFormat, &pfd))
ShowMessage("Pixel format not set");I guess that I got the flags alright. ChoosePixelFormat returns some stuff (so it's not NULL), but SetPixelFormat doesn't work. So I wonder what I did wrong?

So far, my main doubts are about the handle "hdc". In MSDN they operate with DIBsections. - But here, I use Borland's own TBitmap. Borland fans - does anyone know where's the problem? Thanx!

NOAH IV
07-29-2004, 08:45 AM
Well, i've done this before. Not sure, but did you try to use this?


hdc = GetDC(prBM->Canvas->Handle);

Lelik
07-29-2004, 10:17 PM
I tried what you suggested, but it just returns hdc = NULL :(

ijk
07-30-2004, 12:32 AM
Create a new Bitmap :

http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=9;t=000248

But You have to know the openGL hardware doesn't work in a BITMAP (only openGL software)

Lelik
07-30-2004, 01:18 AM
Thank you, I read your code but I was referring to Borland's TBitmap class. The project I'm involved in requires this task to be completed in Borland C++ Builder...

rgpc
07-30-2004, 02:35 AM
I could be wrong, I've never tried rendering direct to a Bitmap (that's what pbuffers are for IMO). But perhaps your Depth bits are causing an issue? Set them to zero and see what happens.

Lelik
07-30-2004, 03:09 AM
Doesn't work either...

Lelik
08-03-2004, 03:24 AM
I think I found out the reason of my troubles... I thought that an empty TBitmap would be ok, but it didn't work. So now I create a TBitmap, then set width and height (by default they are both 0). SetPixelFormat works. Stupid, but true...