Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 993187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:22:53+00:00 2026-05-16T06:22:53+00:00

PIXELFORMATDESCRIPTOR pfd = { /* otherwise fine for a window with 32-bit color */

  • 0


PIXELFORMATDESCRIPTOR pfd = { /* otherwise fine for a window with 32-bit color */ };

HDC hDC = CreateDC(TEXT("Display"),NULL,NULL,NULL); // always OK

int ipf = ChoosePixelFormat(hDC,&pfd); // always OK

SetPixelFormat(hDC,ipf,&pfd); // always OK

HGLRC hRC = wglCreateContext(hDC); // always OK

wglMakeCurrent(hDC,hRC); // ! read error: 0xbaadf039 (debug, obviously)

But the following works with the same hRC:


wglMakeCurrent(hSomeWindowDC,hRC);

The above is part of an OpenGL 3.0+ initialization system for Windows.

I am trying to avoid creating a dummy window for the sake of aesthetics.

I have never used CreateDC before, so perhaps I’ve missed something.

edit: hSomeWindowDC would point to a window DC with an appropriate pixel format.

More info:

I wish to create a window-independent OpenGL rendering context.

Due to the answer selected, it seems I need to use a dummy window (not really a big deal, just a handle to pass around all the same).

Why I would want to do this: Since it is possible to use the same rendering context for multiple windows with the same pixel format in the same thread, it is possible to create a rendering context (really, just a container for gl-related objects) that is independent of a particular window. In this way, one can create a clean separation between the graphics and UI initializations.

The purpose of the context initially isn’t for rendering (although I believe one could render into textures using it). If one wanted to change the contents of a buffer within a particular context, the desired context object itself would just need to be made current (since it’s carrying the dummy window around with it, this is possible). Rendering into a window is simple: As implied by the above, the window’s DC only needs to have the same pixel format. Simply make the rendering context and the window’s DC current, and render.

Please note that, at the time of this writing, this idea is still in testing. I will update this post should this change (or if I can remember 😛 ).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:22:54+00:00Added an answer on May 16, 2026 at 6:22 am

    I’ve got a dormant brain cell from reading Petzold 15 years ago that just sprang back to life. The DC from CreateDC() is restricted. Good for getting info about the display device, measurement, that sort of stuff. Not good to use as a regular painting DC. You almost certainly need GetDC().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ContextWin32::ContextWin32(WindowHandle parent, NLOpenGLSettings settings) : IPlatformContext(parent, settings) { int pf = 0; PIXELFORMATDESCRIPTOR pfd
I would like to create a render context to use opengl. The wglMakeCurrent(hdc, hrc)
Some time ago I started working on OpenGL(3.3) renderer for MFC program.Everything was fine
I'm currently trying to draw a quadratic surface with openGL.When using a single window,my
I am getting weird problem, the crash happens at random times, for example i
i was reading the book Delphi Developer's Guide to OpenGL and this code should
I had this problem a long time ago and recently I got some clues
I have an MFC-driven dialog-based application created with MSVS2005. Here is my problem step
I've just started with opengl but I ran into some strange behaviour. Below I
I'm trying to use opengl in C#. I have following code which fails with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.