1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <wx/notebook.h>
class GL_Window : public wxGLCanvas
{
public:
GL_Window(float c, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style=0,
const wxString& name="GLCanvas", int* attribList = 0, const wxPalette& palette = wxNullPalette)
: wxGLCanvas(parent, id, pos, size, style, name, attribList, palette), c_(c), rotate_(c) {}
virtual ~GL_Window() {}
void draw() {
rotate_ += 0.01;
SetCurrent();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, (GLint)200, (GLint)200);
glColor3f(1.0, c_, c_);
glBegin(GL_POLYGON);
glVertex3f(-0.5, -0.5, 5*cos(rotate_));
glVertex3f(-0.5, 0.5, 5*cos(rotate_));
glVertex3f(0.5, 0.5, -5*cos(rotate_));
glVertex3f(0.5, -0.5, -5*cos(rotate_));
glEnd();
SwapBuffers();
}
void OnIdle(wxIdleEvent& event) {
draw();
event.RequestMore();
}
private:
float c_;
float rotate_;
DECLARE_EVENT_TABLE();
};
class MyApp: public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame* frame = new wxFrame((wxFrame *)NULL, -1, "Hello GL World", wxPoint(50,50), wxSize(450,340) );
wxNotebook* book = new wxNotebook(frame, -1, wxPoint(-1,-1), wxSize(200,200));
GL_Window* MyGLCanvas = new GL_Window(1, book, -1, wxPoint(-1,-1), wxSize(200,200), wxSUNKEN_BORDER, "some text");
book->AddPage(MyGLCanvas, "One");
MyGLCanvas = new GL_Window(0, book, -1, wxPoint(-1,-1), wxSize(200,200), wxSUNKEN_BORDER, "some text");
book->AddPage(MyGLCanvas, "Two");
frame->Show(TRUE);
return TRUE;
}
BEGIN_EVENT_TABLE(GL_Window, wxGLCanvas)
EVT_IDLE(GL_Window::OnIdle)
END_EVENT_TABLE() |
Partager