wxOGL

January 26, 2007 at 12:48 am Leave a comment

This is just a adaption from the one existing in wxPyWiki to the c++ language. It will include al least the information posted there and any other you will like to contributed. Some parts has been just copy-paste, my apologize if this violate some copyrights. Anyway I like to thanks the contributors from the wiki described above.

Status

Development Status

  • OGL development appears to be dead.
  • There does not appear to be OGL maintenance.
  • Object Graphics Library (OGL) is a C++ library supporting the creation and manipulation of simple and complex graphic images on a canvas. It can be found in the directory $WX_PATH/contrib/ogl/src in the wxWidgets distribution. The file ogl.h must be included to make use of the library.

    Documentation Status

    The standard OGL documentation is old and erronius.

  • http://biolpc22.york.ac.uk/wx/contrib/docs/html/ogl/ogl.htm
  • Standard OGL docs consist of:

  • class library documentation
  • notes
  • a complicated sample
  • This wiki entry is an effort to fix the situation.

    If you are using OGL, please post your notes and corrections to this wiki page..!

    Sample code

    Minimal wxOGL Application

    This is a minimal application demonstrating wxOGL, contributed by LionKimbro


    #include "wx/wx.h"
    #include "wx/ogl/ogl.h"class MyApp: public wxApp
    {
    virtual bool OnInit();
    };
    class MyFrame: public wxFrame
    {
    public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    };
    IMPLEMENT_APP(MyApp)
    bool MyApp::OnInit()
    {
    MyFrame *frame = new MyFrame( "wxWidgets - Object Graphics Library", wxPoint(50,50), wxSize(450,340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
    return TRUE;
    }
    MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
    : wxFrame((wxFrame *)NULL, -1, title, pos, size)
    {
    wxShapeCanvas *canvas = new wxShapeCanvas(this, wxID_ANY, pos, size, 0, wxT("a"));
    canvas->SetBackgroundColour(*wxWHITE);
    canvas->SetCursor(wxCursor(wxCURSOR_CROSS));
    wxDiagram *diagram = new wxDiagram();
    canvas->SetDiagram(diagram);
    wxCircleShape *shape = new wxCircleShape(20.0);
    shape->SetX(25.0);
    shape->SetY(25.0);
    canvas->AddShape(shape);
    diagram->ShowAll(1);
    }

    The above code just create the wxShapeCanvas and graph a circle on it. Although that not so much that will help you get started.

    Mouse event in circle

    This example code, let you define some events in the shape, for example It has implemented the left ans right click.

    #include "wx/wx.h"
    #include "wx/ogl/ogl.h"
    class MyApp: public wxApp
    {
    virtual bool OnInit();
    };
    class OGLFrame: public wxFrame
    {
    public:
    OGLFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    };
    class OGLCanvas: public wxShapeCanvas
    {
    public:
    OGLCanvas(wxWindow *parent = NULL, wxWindowID id = wxID_ANY,const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,long style = wxRETAINED);
    ~OGLCanvas(void);
    };
    class MyEvtHandler: public wxShapeEvtHandler
    {
    public:
    MyEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL,
    const wxString& lab = wxEmptyString):wxShapeEvtHandler(prev, shape) {}
    ~MyEvtHandler(void) {}
    void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
    void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
    };
    IMPLEMENT_APP(MyApp)
    bool MyApp::OnInit()
    {
    OGLFrame *frame = new OGLFrame( "wxOGL", wxPoint(50,50), wxSize(450,340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
    return TRUE;
    }
    OGLFrame::OGLFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
    : wxFrame((wxFrame *)NULL, -1, title, pos, size)
    {
    OGLCanvas *canvas = new OGLCanvas(this);
    }
    OGLCanvas::OGLCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos,
    const wxSize& size, long style):
    wxShapeCanvas(parent, id, pos, size, style)
    {
    SetBackgroundColour(*wxWHITE);
    SetCursor(wxCursor(wxCURSOR_CROSS));
    wxDiagram *diagram = new wxDiagram();
    SetDiagram(diagram);
    wxCircleShape *circle = new wxCircleShape(100);
    circle->SetX(200);
    circle->SetY(200);
    AddShape(circle);
    diagram->ShowAll(1);
    MyEvtHandler *evthandler = new MyEvtHandler();
    evthandler->SetShape(circle);
    evthandler->SetPreviousHandler(circle->GetEventHandler());
    circle->SetEventHandler(evthandler);
    }
    OGLCanvas::~OGLCanvas(void)
    {
    }
    void MyEvtHandler::OnLeftClick(double WXUNUSED(x), double WXUNUSED(y), int keys, int WXUNUSED(attachment))
    {
    wxMessageBox(wxT("Left click"),
    wxT("wxOGL"), wxOK | wxICON_INFORMATION);
    }
    void MyEvtHandler::OnRightClick(double WXUNUSED(x), double WXUNUSED(y), int keys, int WXUNUSED(attachment))
    {
    wxMessageBox(wxT("Right click"),
    wxT("wxOGL"), wxOK | wxICON_INFORMATION);
    }

    Compiling sample code

    Although this is a very basic thing, maybe some newbies like I was (or am?) need it.

    g++ ogl.cpp -o ogl `wx-config --libs` `wx-config --cxxflags` -lwx_gtk2_ogl-2.8

    Advertisements

    Entry filed under: wxWidgets.

    Hello world! Adding a Lexer to wxStyledTextCtrl

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    Trackback this post  |  Subscribe to the comments via RSS Feed


    Recent Posts


    %d bloggers like this: