McLovin
McLovin

Reputation: 3417

Multisampled framebuffer in OpenGL under Windows

How do I set the number of samples in the default framebuffer, given by Windows?

I found this page, but although I use glew, there is no available wglChoosePixelFormatARB function in my context. What could be the cause of this?

Upvotes: 1

Views: 365

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213338

With WGL, you can only set the pixel format for a window once when you create the context, and you can only call the wglChoosePixelFormatARB() function once the client driver is loaded, and the client driver is only loaded once you have an OpenGL context. Yes, that's circular. So, this means you have to do the following:

  1. Create a window with an OpenGL context.

  2. Get the function pointer for wglChoosePixelFormatARB().

  3. Destroy the window, and create a new window with the desired pixel format.

If you've got any sense in you, you'll use SDL or GLFW to do this for you, because it's just a bunch of plumbing you have to write, there's no value in learning how to do it, and you probably want to get some real work done. SDL/GLFW/etc. is how 99% of the OpenGL game devs out there do it.

If you really want to do this yourself and get stuck, look at the SDL or GLFW source code to see how they do it.

  • In SDL, the src/video/windows/SDL_windowsopengl.c file has a function WIN_GL_ChoosePixelFormatARB() which does what you want. Also note the function WIN_GL_LoadLibrary().

  • In GLFW, the src/win32_window.c file has a function _glfwPlatformCreateWindow() which does what you want.

P.S. GLEW is a bit broken with core contexts and modern cards, so watch out. There are other GL loaders out there.

Upvotes: 2

Related Questions