首页 > 其他 > 详细

wxWidgets 动态绑定

时间:2020-09-15 20:05:25      阅读:60      评论:0      收藏:0      [点我收藏+]
#include <wx/wx.h>
#include <wx/glcanvas.h>

class GLCanvas : public wxGLCanvas
{
public:
    GLCanvas(wxWindow* parent, wxGLAttributes & attr)
        :wxGLCanvas(parent, attr)
    {
        wxGLContextAttrs contextAttrs;
        contextAttrs.PlatformDefaults().OGLVersion(4, 0).EndList();

        m_pGLContext = new wxGLContext(this, nullptr, &contextAttrs);

      
        Bind(wxEVT_IDLE, &GLCanvas::OnIdle, this, wxID_ANY);
       
    }

    void OnIdle(wxIdleEvent& event)
    {
        SetCurrent(*m_pGLContext);
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        SwapBuffers();

        event.RequestMore();
    }

private:
    wxGLContext* m_pGLContext;
};


#define BTN_SCALE_ID 5000
class MyApp : public wxApp
{
public:
    virtual bool OnInit()
    {
        wxFrame* frame = new wxFrame(nullptr, wxID_ANY, "opengl");
        wxGLAttributes attr;
        attr.PlatformDefaults().Defaults().DoubleBuffer().EndList();
        wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
        GLCanvas* canvas = new GLCanvas(frame, attr);

        wxBoxSizer* toolSizer = new wxBoxSizer(wxVERTICAL);
        btnRot = new wxButton(frame, BTN_SCALE_ID, wxT("Rot"));

        Bind(wxEVT_BUTTON, &MyApp::OnRot, this, BTN_SCALE_ID);
        btnScale = new wxButton(frame, wxID_ANY, wxT("Scale"));
        toolSizer->Add(btnRot, wxSizerFlags().Expand());
        toolSizer->Add(btnScale, wxSizerFlags().Expand());
        sizer->Add(toolSizer, wxSizerFlags(1).Expand());
        sizer->Add(canvas, wxSizerFlags(5).Expand());

        frame->SetSizer(sizer);
        frame->SetSize(1024, 800);
        frame->Show();


        return true;
    }

    void OnRot(wxCommandEvent & event)
    {

    }
private:
    wxButton* btnRot;
    wxButton* btnScale;
    
};




int main()
{
    MyApp* app = new MyApp;
    wxApp::SetInstance(app);
    return wxEntry();
}

  

wxWidgets 动态绑定

原文:https://www.cnblogs.com/linuxui/p/13674482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!