WxWidgets和现代opengl(3.3+)

时间:2016-12-14 14:26:38

标签: user-interface opengl wxwidgets

有没有人知道WxWidgets库是否能与现代着色器样式openGL(3.3+)一起使用?我发现的所有东西似乎都在使用旧式。我希望在我的应用程序中使用QT或WxWidgets,但似乎使用着色器来处理小部件可能是一场噩梦。有没有人有这方面的经验?

1 个答案:

答案 0 :(得分:3)

在wxWidgets> = 3.1中使用wxGLContext并使用适当的核心上下文wxGLContextAttrs应该有效:

wxGLContextAttrs cxtAttrs;
cxtAttrs.CoreProfile().OGLVersion(3, 3).EndList();

来自Ripi2 pointed outpyramid sample

//We create a wxGLContext in this constructor.
//We do OGL initialization at OnSize().
MyGLCanvas::MyGLCanvas(MyFrame* parent, const wxGLAttributes& canvasAttrs)
                       : wxGLCanvas(parent, canvasAttrs)
{
    m_parent = parent;

    m_oglManager = NULL;
    m_winHeight = 0; // We have not been sized yet

    // Explicitly create a new rendering context instance for this canvas.
    wxGLContextAttrs ctxAttrs;
#ifndef __WXMAC__
    // An impossible context, just to test IsOk()
    ctxAttrs.PlatformDefaults().OGLVersion(99, 2).EndList();
    m_oglContext = new wxGLContext(this, NULL, &ctxAttrs);

    if ( !m_oglContext->IsOK() )
    {
#if wxUSE_LOGWINDOW
        wxLogMessage("Trying to set OpenGL 99.2 failed, as expected.");
#endif // wxUSE_LOGWINDOW
        delete m_oglContext;
        ctxAttrs.Reset();
#endif //__WXMAC__
        ctxAttrs.PlatformDefaults().CoreProfile().OGLVersion(3, 2).EndList();
        m_oglContext = new wxGLContext(this, NULL, &ctxAttrs);
#ifndef __WXMAC__
    }
#endif //__WXMAC__

    if ( !m_oglContext->IsOK() )
    {
        wxMessageBox("This sample needs an OpenGL 3.2 capable driver.\nThe app will end now.",
                     "OpenGL version error", wxOK | wxICON_INFORMATION, this);
        delete m_oglContext;
        m_oglContext = NULL;
    }
    else
    {
#if wxUSE_LOGWINDOW
        wxLogMessage("OpenGL Core Profile 3.2 successfully set.");
#endif // wxUSE_LOGWINDOW
    }

}