如何为 wxWidgets OpenGL 程序启用多重采样?

发布于 2024-07-04 10:12:03 字数 617 浏览 8 评论 0原文

多重采样是应用全屏的一种方式3D 应用程序中的抗锯齿 (FSAA)。 我需要在我的 OpenGL 程序中使用多重采样,该程序当前嵌入在 wxWidgets GUI 中。 有没有办法做到这一点? 仅当您知道实现此目的的详细步骤时才请回复。

我知道使用 WGL< 启用多重采样/a> (Win32 对 OpenGL 的扩展)。 但是,由于我的 OpenGL 程序不是用 MFC 编写的(并且我希望代码可以跨平台移植),所以这对我来说不是一个选择。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱,才寂寞 2024-07-11 10:12:03

我终于在我的 wxWidgets OpenGL 程序中实现了多重采样。 现在有点混乱,但具体情况如下:

wxWidgets 目前在其稳定版本中没有多重采样支持(最新版本在此)时间为2.8.8)。 但是,它可以作为补丁提供,也可以通过他们的每日快照提供。 (后者令人振奋,因为这意味着补丁已被接受,如果没有问题,应该会出现在以后的稳定版本中。)

因此,有 2 个选项:

  1. 从他们的 每日快照

  2. 获取补丁 用于您工作的 wxWidgets 安装。

我发现第二个选项不太麻烦,因为我不想尽可能地干扰我的工作安装。 如果您不知道如何在 Windows 上打补丁,请参阅

至少,对于 Windows,该补丁将修改以下文件:

$(WX_WIDGETS_ROOT)/include/wx/glcanvas.h
$(WX_WIDGETS_ROOT)/include/wx/msw/glcanvas.h
$(WX_WIDGETS_ROOT)/src/msw/glcanvas.cpp

打补丁后,重新编译 wxWidgets 库。

要在您的 wxWidgets OpenGL 程序中启用多重采样,需要对代码进行少量更改。

需要将属性列表传递给 wxGLCanvas 构造函数:

int attribList[] = {WX_GL_RGBA,
                    WX_GL_DOUBLEBUFFER,
                    WX_GL_SAMPLE_BUFFERS, GL_TRUE, // Multi-sampling
                    WX_GL_DEPTH_SIZE, 16,
                    0, 0};

如果您已经在使用属性列表,则向其中添加带有 GL_SAMPLE_BUFFERS, GL_TRUE 的行。 否则,请将此属性列表定义添加到您的代码中。

然后修改您的 wxGLCanvas 构造函数,以将此属性列表作为参数:

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)
{
    // ...
}

创建 wxGLCanvas 元素后,默认情况下会打开多重采样。 要随意禁用或启用它,请使用相关的 OpenGL 调用:

glEnable(GL_MULTISAMPLE);
glDisable(GL_MULTISAMPLE);

多重采样现在应该与 wxWidgets OpenGL 程序一起使用。 希望 wxWidgets 的稳定版本很快就会支持它,从而使此信息变得无关紧要:-)

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:

  1. Download and build from their daily snapshot.

  2. 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 :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文