WxOGL
From WxWiki
This wiki is just a adaption from the one existing in wxPyWiki [1] 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.
Contents |
[edit] Status
[edit] Development Status
[edit] Documentation Status
The standard OGL documentation is old and erronius.
[edit] Sample code
[edit] 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.
[edit] 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);
}
[edit] 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
