PDA

View Full Version : PIXELFORMATDESCRIPTOR



pietro1
06-20-2003, 07:54 AM
Hello:

I am trying to have OpenGL draw to a memory Bitmap (created using GDI+). I am requesting a PIXELFORMATDESCRIPTOR with the following dwFlags:
- PFD_DRAW_TO_BITMAP
- PFD_SUPPORT_OPENGL
- PFD_SUPPORT_GDI

ChoosePixelFormat returns a pixel format index of 8. DescribePixelFormat tells me that the dwFlags for this index are:
- PFD_DRAW_TO_WINDOW
- PFD_DRAW_TO_BITMAP
- PFD_SUPPORT_OPENGL
- PFD_SUPPORT_GDI
- PFD_SUPPORT_GENERIC_FORMAT

When the image is drawn it is drawn to the window instead of the bitmap.

It would be greatly appreciated if anyone can tell me why OpenGL is drawing to the window instead of the bitmap.

Deiussum
06-20-2003, 08:48 AM
I'm probably just asking the obvious, but you are using the handle to the BMP rather than the handle to the Window, right?

Some other questions, just to get an idea of what you are doing:

Are you using C++, C#, VB.Net?

I haven't worked with GDI+ too extensively, but in GDI, you don't actually get an HDC to a bitmap. You create a memory DC, select a BMP into it, and use that DC with the PixelFormatDescriptor stuff.

I've been working a bit with my own Managed C++ wrapper for OpenGL so that I can play with it a bit in C#, so maybe if I get the chance, I'll try it out with GDI+ and find out what I can for you.

Edit: One other thought.. How are you creating your GDI+ BMP object? Is it something that you dragged and dropped onto your window, or do you just create an instance of it in memory?

Edit2: Just created a quick C# app so that I could check out it's encapsulation of the GDI+ Bitmap object. I'm not seeing any sort of handle on it that you could use directly in the pixelformat functions. Maybe the GDI+ API is a bit different in C++, but I've only really done GDI+ stuff in C#. How exactly are you specifying the pixelformat of the BMP?

[This message has been edited by Deiussum (edited 06-20-2003).]

pietro1
06-23-2003, 04:11 AM
Thank you for your reply

I am developing in C++.

The GDI+ bitmap is created by creating an instance of it.
Graphics tmpGDI(m_hWnd);
CRect client;GetClientRect(client);
m_pBitmap = new Bitmap(client.Width(), client.Height(), &tmpGDI);

I am specifying the PIXELFORMATDESCRIPTOR like this:
m_pPixelDesc = new PIXELFORMATDESCRIPTOR;
memset(m_pPixelDesc, 0, sizeof(PIXELFORMATDESCRIPTOR));
m_pPixelDesc->nSize = sizeof(PIXELFORMATDESCRIPTOR);
m_pPixelDesc->nVersion = 1;
m_pPixelDesc->dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
m_pPixelDesc->iPixelType = PFD_TYPE_RGBA;
m_pPixelDesc->cColorBits = 32;
m_pPixelDesc->cRedBits = 0;
m_pPixelDesc->cRedShift = 0;
m_pPixelDesc->cGreenBits = 0;
m_pPixelDesc->cGreenShift = 0;
m_pPixelDesc->cBlueBits = 0;
m_pPixelDesc->cBlueShift = 0;
m_pPixelDesc->cAlphaBits = 0;
m_pPixelDesc->cAlphaShift = 0;
m_pPixelDesc->cAccumBits = 0;
m_pPixelDesc->cAccumRedBits = 0;
m_pPixelDesc->cAccumGreenBits = 0;
m_pPixelDesc->cAuxBuffers = 0;
m_pPixelDesc->iLayerType = PFD_MAIN_PLANE;
m_pPixelDesc->bReserved = 0;
m_pPixelDesc->dwLayerMask = 0;
m_pPixelDesc->dwVisibleMask = 0;
m_pPixelDesc->cAccumBlueBits = 0;
m_pPixelDesc->cAccumAlphaBits = 0;
m_pPixelDesc->cDepthBits = 0;
m_pPixelDesc->cStencilBits = 0;
m_pPixelDesc->dwDamageMask = 0;

Deiussum
06-23-2003, 04:52 AM
Ok, but how are you assigning your PIXELFORMATDESCRIPTOR to your Bitmap? From what I can see, there's no way to get an HDC for a Bitmap, and you need an HDC for Choose/Describe/SetPixelFormat.

Instead, maybe you should try to use CreateCompatibleDC to create a memory DC, get an HBITMAP for your Bitmap, and do a SelectObject to place that in the memory DC. Then you can use the HDC to the memory DC in your Choose/Describe/SetPixelFormat calls.

As I've said, I haven't done much with GDI+, so maybe there's something similar to that you can do using GDI+ object.

pietro1
06-23-2003, 05:10 AM
I have the Graphics object to be created as follows:

HDC memDC = CreateCompatibleDC(GetDC()->m_hDC);
Graphics tmpGDI(memDC);

And am using memDC in
::ChoosePixelFormat(memDC, m_pPixelDesc);
and
::SetPixelFormat(memDC, m_nPixelIndex, m_pPixelDesc);

ChoosePixelFormat returns and index of 8, and SetPixelFormat returns FALSE with an error code of 1 - (Incorrect function)

Deiussum
06-23-2003, 09:27 AM
Try and use DescribePixelFormat between Choose and Set to make sure the PIXELFORMATDESCRIPTOR is fully filled in correct.