问题
Multisampling is a way of applying full screen anti-aliasing (FSAA) in 3D applications. I need to use multisampling in my OpenGL program, which is currently embedded in a wxWidgets GUI. Is there a way to do this? Please respond only if you know the detailed steps to achieve this.
I'm aware of enabling multisampling using WGL (Win32 extensions to OpenGL). However, since my OpenGL program isn't written in MFC (and I want the code to be multi-platform portable), that's not an option for me.
回答1:
I finally got Multisampling working with my wxWidgets OpenGL program. It's a bit messy right now, but here's how:
wxWidgets doesn't have Multisampling support in their stable releases right now (latest version at this time is 2.8.8). But, it's available as a patch and also through their daily snapshot. (The latter is heartening, since it means that the patch has been accepted and should appear in later stable releases if there are no issues.)
So, there are 2 options:
Download and build from their daily snapshot.
Get the patch for your working wxWidgets installation.
I found the 2nd option to be less cumbersome, since I don't want to disturb my working installation as much as possible. If you don't know how to patch on Windows, see this.
At the very least, for Windows, the patch will modify the following files:
$(WX_WIDGETS_ROOT)/include/wx/glcanvas.h
$(WX_WIDGETS_ROOT)/include/wx/msw/glcanvas.h
$(WX_WIDGETS_ROOT)/src/msw/glcanvas.cpp
After patching, recompile the wxWidgets libraries.
To enable multisampling in your wxWidgets OpenGL program, minor changes to the code are required.
An attribute list needs to be passed to the wxGLCanvas constructor:
int attribList[] = {WX_GL_RGBA,
WX_GL_DOUBLEBUFFER,
WX_GL_SAMPLE_BUFFERS, GL_TRUE, // Multi-sampling
WX_GL_DEPTH_SIZE, 16,
0, 0};
If you were already using an attribute list, then add the line with GL_SAMPLE_BUFFERS, GL_TRUE
to it. Else, add this attribute list definition to your code.
Then modify your wxGLCanvas constructor to take this attribute list as a parameter:
myGLFrame::myGLFrame // Derived from wxGLCanvas
(
wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name
)
: wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name, attribList)
{
// ...
}
After the wxGLCanvas element is created, multisampling is turned on by default. To disable or enable it at will, use the related OpenGL calls:
glEnable(GL_MULTISAMPLE);
glDisable(GL_MULTISAMPLE);
Multisampling should now work with the wxWidgets OpenGL program. Hopefully, it should be supported in the stable release of wxWidgets soon, making this information irrelevant :-)
来源:https://stackoverflow.com/questions/21560/how-to-enable-multisampling-for-a-wxwidgets-opengl-program