Advertisement Jump to content


This topic is now archived and is closed to further replies.


Memory Device Contexts

This topic is 5543 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to create, and render to a memory device context in opengl. When i try to do this my computer restarts when i try to set the pixel format. Below is the code (its in OO-Pascal but it should be pretty obvious whats going on to all you c++ people):
procedure TForm1.FormCreate(Sender: TObject);
  DC: HDC;
  Bitmap: HBITMAP;
  PixFormat: Cardinal;
  PixDesc: TPixelFormatDescriptor;

  FillChar( PixDesc, sizeof(PixDesc), 0 );

  with PixDesc do
    nSize        := sizeof(TPixelFormatDescriptor);
    nVersion     := 1;
    iPixelType   := PFD_TYPE_RGBA;
    cColorBits   := 32;
    cDepthBits   := 16;
    cStencilBits := 0;
    iLayerType   := PFD_MAIN_PLANE;

  DC := CreateCompatibleDC(0);

  Bitmap := CreateCompatibleBitmap( DC, 1, 1 );

  SelectObject( DC, Bitmap );

  PixFormat := ChoosePixelFormat( DC, @PixDesc );

  SetPixelFormat( DC, PixFormat, @PixDesc );

Thanks for any help you can offer

Share this post

Link to post
Share on other sites
when you set your pixel format descriptor, you can choose to render to a bitmap (one of those unsupported ones).

A really cheap and dirty work around is to make a panel, make it non-visible, and use it''s hand with for the hdc. something like


or whatever the function is.

You can render to it pretty easily then. If you need to read the data off it, I recommend using glreadpixels in either the GL_BITMAP or the GL_UNSIGNED_BYTE format instead of reading from the panel''s bitmap.

Either way, you won''t need to double or triple buffer it as just glClear functions and glreadpixels don''t need it.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!