Embedding OGRE in wxWidgets 2.8         Quick guide to embedding Ogre in wxWidgets 2.8

What is wxWidgets?

wxWidgets is a cross-platform GUI library (wxWindows License (like L-GPL)).

Step 1: Setup wxWidgets

After downloading and installing wxWidgets 2.8, we may create an environment variable called WXWIN and set it to the installation directory (including drive letter).

Then open ($WXWin)\build\msw\wx.dsw and click build solution (for release and debug configurations).

Step 2: Create OGRE Project

We may use OGRE SDK AppWizard, choosing Empty Project at Application Settings page.

Step 3: Add source files to our project

We will add wxOgre.h and wxOgre.cpp from WxOgre for OGRE v1.2 plus:
app.h

#ifndef APP_H
#define APP_H

#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

class MyApp : public wxApp
{
    public:
        virtual bool OnInit();
};

#endif // APP_H


main.h

#ifndef MAIN_H
#define MAIN_H

#include "app.h"
#include "wxOgre.h"

class MyFrame: public wxFrame
{
    public:
        MyFrame(wxFrame *frame, const wxString& title);
        ~MyFrame();
        void UpdateOgre()
    {
        wxOgrePane->update();
    }
    private:
        wxOgre* wxOgrePane;
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        DECLARE_EVENT_TABLE();
};

#endif // MAIN_H


app.cpp

#include "app.h"
#include "main.h"

#include "wxOgre.h"

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    MyFrame* frame = new MyFrame(0L, _("wxWidgets Application Template"));
    frame->Show();
    frame->UpdateOgre();
    return true;
}


main.cpp

#include "main.h"

int idMenuQuit = wxNewId();
int idMenuAbout = wxNewId();

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(idMenuQuit, MyFrame::OnQuit)
    EVT_MENU(idMenuAbout, MyFrame::OnAbout)
END_EVENT_TABLE()

MyFrame::MyFrame(wxFrame *frame, const wxString& title)
    : wxFrame(frame, -1, title)
{

    // create a menu bar
    wxMenuBar* mbar = new wxMenuBar();
    wxMenu* fileMenu = new wxMenu(_T(""));
    fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
    mbar->Append(fileMenu, _("&File"));

    wxMenu* helpMenu = new wxMenu(_T(""));
    helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
    mbar->Append(helpMenu, _("&Help"));

    SetMenuBar(mbar);

    // create a status bar with some information about the used wxWidgets version
    CreateStatusBar(2);
    SetStatusText(_("Hello Code::Blocks user !"),0);
    SetStatusText("Hello Code::Blocks user !",1);

        
    wxOgrePane = new wxOgre(this);

}

MyFrame::~MyFrame()
{
}

void MyFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = _("Welcome to...");
    wxMessageBox(msg, _("Welcome to..."));
}

Step 4: Set Project Properties

Time to setup our project. For debug configuration we will set:

  • Debugging Node:
    • (optional) We may want to remove $(OGRE_HOME) variable from both Command and Working Directory fields. If we do so, we will also copy bin and media folder from OGRE sdk to our project folder.
  • C/C++ Node
    • General: Additional Include Directories field should contain the following:
      • $(WXWIN)\include
      • $(WXWIN)\contrib\include
      • $(WXWIN)\lib\vc_lib\mswd
    • Preprocessor: WIN32 _DEBUG _WINDOWS WINDOWS WXMSW WXDEBUG WXDEBUG=1 WIN95 WIN32 WINVER=0x0400 STRICT
    • Precompiled Headers: The Not using precompiled headers or Automatic use of precompiled headers button should be selected.
    • Code Generation: Runtime Library field should be set to Debug Multithreaded DLL.
  • Linker Node
    • General: Additional Library Directories field should contain the following:
      • $(WXWIN)\lib\vc_lib
      • $(WXWIN)\contrib\lib
    • Input: Add the following to Additional Dependencies field: wxmsw28d_core.lib wxbase28d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib


And for release configuration:

  • C/C++ Node
    • General: Additional Include Directories field should contain the following:
      • $(WXWIN)\include
      • $(WXWIN)\contrib\include
      • $(WXWIN)\lib\vc_lib\msw
    • Preprocessor: NDEBUG WIN32 _WINDOWS WINDOWS WXMSW WIN95 WIN32 WINVER=0x0400 STRICT
    • Precompiled Headers: The Not using precompiled headers or Automatic use of precompiled headers button should be selected.
    • Code Generation: Runtime Library field should be set to Multithreaded DLL.
  • Linker Node
    • General: Additional Library Directories field should contain the following:
      • $(WXWIN)\lib\vc_lib
      • $(WXWIN)\contrib\lib
    • Input: Add the following to Additional Dependencies field: wxmsw28_core.lib wxbase28.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib


Thats was all. if you have any suggestions for improvements, or find any error, then please post in this forum thread. Thank you.