Results 1 to 6 of 6

Thread: PIXELFORMATDESCRIPTOR

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2003
    Location
    Rochester, NY USA
    Posts
    3

    PIXELFORMATDESCRIPTOR

    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.
    ~~pietro

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: PIXELFORMATDESCRIPTOR

    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).]
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2003
    Location
    Rochester, NY USA
    Posts
    3

    Re: PIXELFORMATDESCRIPTOR

    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;
    ~~pietro

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: PIXELFORMATDESCRIPTOR

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2003
    Location
    Rochester, NY USA
    Posts
    3

    Re: PIXELFORMATDESCRIPTOR

    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)
    ~~pietro

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: PIXELFORMATDESCRIPTOR

    Try and use DescribePixelFormat between Choose and Set to make sure the PIXELFORMATDESCRIPTOR is fully filled in correct.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. About PIXELFORMATDESCRIPTOR
    By Meu in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 05-29-2005, 02:39 PM
  2. confused : PixelFormatDescriptor
    By Super13 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-14-2003, 10:02 PM
  3. PIXELFORMATDESCRIPTOR problems
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-11-2002, 09:24 AM
  4. Replies: 2
    Last Post: 12-03-2002, 03:01 AM
  5. PIXELFORMATDESCRIPTOR Blues
    By Shag in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 01-27-2002, 12:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean