Mason Wheeler
Mason Wheeler

Reputation: 84540

Delphi form gives a bad pixel format for OpenGL

I'm using the SDL library to try to create a rendering context in a Delphi form. Everything works well until I try to create the renderer itself. It calls wglCreateContext, which fails. The error message says "Invalid pixel format."

The pixel format is based on the hdc for the form, which is all set up and managed internally by the VCL. Does anyone know how to figure out what's going wrong and correct it?

Upvotes: 0

Views: 680

Answers (1)

Paul-Jan
Paul-Jan

Reputation: 17278

The pixel format is based on the hdc for the form

From this statement, I can't really tell if you are already using ChoosePixelFormat... but you really want to set your own particular pixelformat with the PFD_SUPPORT_OPENGL flag enabled, and not use the default one from the HDC.

In short, here is what you do:

  1. Get the hdc from the canvas
  2. Initialize your own PixelFormatDescriptor
  3. Use ChoosePixelFormat to match that descriptor to an available pixelFormat
  4. Use SetPixelFormat to set that pixelFormat on the hdc
  5. Use wlCreateContext to get your context
  6. Use ActivateRenderingContext to get cracking.

For the pixelFormatDescriptor, use

  • flags PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
  • pixelType PFD_TYPE_RGBA
  • a sensible ColorBits and DepthBits.

If you somehow specify a wrong format, either step 3 or 4 will break and tell you what went wrong. Hope that helps!

If you are already doing all this... well, perhaps you can post the details of your formatDescriptor setup code, so we can see what is going on.

Upvotes: 2

Related Questions