Using DirectX with wxWidget


A.K.A. wxWindow is a cross-platform toolkit for creating window application. There is a class called
wxGLCanvas for OpenGL, but no information for DirectX. Then, I try to integrate DirectX with wxWidgets. I found flick will happen when I use paint event to draw d3d frame. To avoid from flicking, I use erase event to clear the background of window and redraw d3d frame. Here is the pseudo code:

class MyApp : public wxApp
    virtual bool OnInit();
    virtual int OnExit();

class MyViewport : public wxPanel
    MyViewport(wxWindow* parent);
    void OnIdle(wxIdleEvent& event);
    void OnDraw(wxEraseEvent& event);

class MyFrame: public wxFrame
    MyViewport *mpViewport;
    MyFrame(const wxString& title);

// the event tables connect the wxWidgets events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(MyViewport, wxPanel)
EVT_IDLE (MyViewport::OnIdle)

// Create a new application object: this macro will allow wxWidgets to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also implements the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and not wxApp)

// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
    // create the main application window
    MyFrame *frame = new MyFrame( _T("D3D sample") );

    create D3D device here

    return true;

int MyApp::OnExit()
    release D3D device here
    return wxApp::OnExit();

// frame constructor
MyFrame::MyFrame(const wxString& title) :
wxFrame(NULL, -1, title, wxPoint(0,0)), mpViewport(NULL), mpTreeCtrl(NULL)
    mpViewport = new MyViewport(this);

MyViewport::MyViewport(wxWindow* parent) : wxPanel(parent)

void MyViewport::OnIdle(wxIdleEvent& event)
    update your d3d objects here

    // call Refresh() to send a wxEraseEvent to redraw a frame

void MyViewport::OnDraw(wxEraseEvent& event)

    draw your d3d objects here

    g_pd3dDevice->Present(NULL,NULL, this->GetHWND() ,NULL);

DirectX 응용 프로그램에 wxWidget을 사용하는 방법에 대한 코드. 최근에는 wxEntry 가 추가되어 위의 코드와는 조금 다를지도 모르겠다. 그냥 이런 부분을 신경 써야 하는구나 - 정도로 읽으면 되겠다. 실제로 wxWidget을 사용하여 제대로 된 툴을 만들고 싶으신 분들은 Nocturnal Initiative에 관심을 가질 것.

by kimsama | 2007/12/17 17:45 | Development | 트랙백 | 핑백(1) | 덧글(0)

트랙백 주소 :
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Linked at East Agent's Blo.. at 2008/12/27 21:13

... 늦은 저녁에 T와 잡담하다 이 책 이야기가 나와서 문득 생각이 미쳐 올립니다. (그런데 이미 강컴에는 장기품절로 나오는군요. 알아서들 구하시길~ ^^:) @@ "Using DirectX with wxWidget" - DirectX 응용프로그램에서 wxWidget을 사용하는 방법에 대한 code snip. ... more

:         :


비공개 덧글

◀ 이전 페이지다음 페이지 ▶