Code: Select all
#include "wx/wx.h";
#include "wx/notebook.h";
#include <glew.h>
#include <wx/glcanvas.h>
// Declare the application class
class MyApp : public wxApp
{
public:
bool render_loop_on;
virtual bool OnInit();
};
// Implements MyApp& GetApp()
DECLARE_APP(MyApp)
// Give wxWidgets the means to create a MyApp object
IMPLEMENT_APP(MyApp)
// Declare our main frame class
class MyFrame : public wxFrame
{
public:
/*wxNotebook* nbHierarchy = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300));
wxNotebook* nbScene = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(800, 600));
wxNotebook* nbInspector = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300));*/
// Constructor
MyFrame(const wxString& title);
// Event handlers
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
wxGLContext* myContext;
wxGLCanvas* myCanvas;
wxPanel* panel;
private:
// This class handles events
DECLARE_EVENT_TABLE()
};
// Initialize the application
bool MyApp::OnInit()
{
// Create the main application window
MyFrame *frame = new MyFrame(wxT("War Engine Version 0"));
// Show it
frame->Show(true);
return true;
}
// Event table for MyFrame
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_SIZE(MyFrame::OnSize)
EVT_PAINT(MyFrame::OnPaint)
wxEND_EVENT_TABLE()
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxString msg;
msg.Printf(wxT("Hello and welcome to %s."),
"War Engine Version 0");
wxMessageBox(msg, wxT("About War Engine"),
wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
// Destroy the frame
Close();
}
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// Create a menu bar
wxMenu *fileMenu = new wxMenu;
// The “About” item should be in the help menu
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
wxT("ABout this program."));
fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt - X"),
wxT("Quit this program"));
// Now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, wxT("&File"));
menuBar->Append(helpMenu, wxT("&Help"));
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
// Create a status bar just for fun
CreateStatusBar(2);
SetStatusText(wxT("Welcome to War Engine!"));
panel = new wxPanel(this);
wxGLAttributes vAttrs;
// Defaults should be accepted
vAttrs.PlatformDefaults().Defaults().EndList();
bool accepted = wxGLCanvas::IsDisplaySupported(vAttrs);
if (accepted)
{
myCanvas = new wxGLCanvas(panel, vAttrs);
}
wxGLContextAttrs ctxAttrs;
ctxAttrs.PlatformDefaults().CoreProfile().OGLVersion(3, 2).EndList();
myContext = new wxGLContext(myCanvas, NULL, &ctxAttrs);
myCanvas->SetCurrent(*myContext);
glewExperimental = true;
GLenum err = glewInit();
if (GLEW_OK != err)
{
wxMessageBox("GLEW not initialized");
}
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(panel, 1, wxEXPAND);
sizer->SetSizeHints(this);
SetSizer(sizer);
/*wxPanel* hierarchyWindow = new wxPanel(nbHierarchy, wxID_ANY);
nbHierarchy->AddPage(hierarchyWindow, "Hierarchy", false);
wxPanel* sceneWindow = new wxPanel(nbScene, wxID_ANY);
nbScene->AddPage(sceneWindow, "Game", false);
wxPanel* inspectorWindow = new wxPanel(nbInspector, wxID_ANY);
nbInspector->AddPage(inspectorWindow, "Inspector", false);
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(nbHierarchy, 0, wxEXPAND, 0);
sizer->Add(nbScene, 1, wxEXPAND, 0);
sizer->Add(nbInspector, 0, wxEXPAND, 0);
sizer->SetSizeHints(this);
SetSizer(sizer);*/
}
void MyFrame::OnSize(wxSizeEvent& event)
{
glViewport(0, 0, (GLsizei)event.GetSize().x, (GLsizei)event.GetSize().y);
}
void MyFrame::OnPaint(wxPaintEvent& event)
{
glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
myCanvas->SwapBuffers();
}
I don't see anything that helps me in the sample.