Reputation: 3
I am relatively new to OpenGL and I would like to add anti-aliasing to my C++ Win32 project. I currently get a device context in the window procedure when the WM_CREATE message is received, and then create an OpenGL context using a pixel format descriptor, like this:
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
//...
switch (msg) {
case WM_CREATE:
log("Starting WM_CREATE...");
hDC = GetDC(hWnd);
//Pixel Format
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
format = ChoosePixelFormat(hDC, &pfd);
if (!SetPixelFormat(hDC, format, &pfd)) {
log("Error: Could not set pixel format.");
PostQuitMessage(1);
break;
}
//Create Render Context
hRC = wglCreateContext(hDC);
if (!wglMakeCurrent(hDC, hRC)) {
log("Error: Could not activate render context.");
PostQuitMessage(1);
break;
}
//Initialize GLEW
if (glewInit()) {
log("Error: Could not initialize GLEW.");
PostQuitMessage(1);
break;
}
//Other initialization goes here
//...
break;
//...
}
return 0;
}
In order to get antialiasing to work, I understand that I need to use an extension like WGL_ARB_multisample. There seem to be very few examples of how to actually use this, especially with GLEW. How would I go about modifying my code to get this to work? Thanks.
Upvotes: 0
Views: 1724
Reputation: 45372
GLEW also supports WGL and glX extensions. For wgl, you need the wglew.h
header files. It works the same way as for GL extensions: GLEW will automatically get the functions pointers for wgl extensions with the glewInit()
call.
On windows, what you actually have to do is the following:
Now, WGL_ARB_multisample does not define any wgl extension functions in itself. It just defines new attributes for wglChoosePixelFormatEXT()
from WGL_EXT_pixel_fromat. And that is what you have to call in step 3 to request a pixel format supporting multisampling.
Upvotes: 2