如何为wxWidgets OpenGL程序启用多重采样? [英] How to enable multisampling for a wxWidgets OpenGL program?

查看:164
本文介绍了如何为wxWidgets OpenGL程序启用多重采样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我知道使用 WGL (OpenGL的Win32扩展).但是,由于我的OpenGL程序不是用MFC编写的(并且我希望代码可以是多平台可移植的),所以这不是我的选择.

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.

推荐答案

我终于在wxWidgets OpenGL程序中使用了Multisampling.现在有点混乱,但是方法如下:

I finally got Multisampling working with my wxWidgets OpenGL program. It's a bit messy right now, but here's how:

wxWidgets 目前在其稳定版本中没有多重采样支持(当前最新版本为 2.8.8. ).但是,它可以作为补丁程序使用,也可以通过他们的每日快照获得. (后者令人振奋,因为这意味着该补丁已被接受,如果没有问题,应在以后的稳定版本中显示.)

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

因此,有2个选项:

  1. 从其 每日快照下载并构建 .

获取 修补程序 .

Get the patch for your working wxWidgets installation.

我发现第二个选项不太麻烦,因为我不想尽可能多地打扰我的正常安装.如果您不知道如何在Windows上打补丁,请参见.

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.

至少,对于Windows,此修补程序将修改以下文件:

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

修补后,重新编译 wxWidgets库.

After patching, recompile the wxWidgets libraries.

要在wxWidgets OpenGL程序中启用多重采样,需要对代码进行较小的更改.

To enable multisampling in your wxWidgets OpenGL program, minor changes to the code are required.

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

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};

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

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.

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

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

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

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);

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

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

这篇关于如何为wxWidgets OpenGL程序启用多重采样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆