태그 : wxWidget
원문:
http://phenixyu.blogspot.com/2007/03/using-directx-with-wxwidget.html
wxWidgets 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
{
public:
MyViewport(wxWindow* parent);
void OnIdle(wxIdleEvent& event);
void OnDraw(wxEraseEvent& event);
private:
DECLARE_EVENT_TABLE()
};
class MyFrame: public wxFrame
{
MyViewport *mpViewport;
public:
MyFrame(const wxString& title);
private:
DECLARE_EVENT_TABLE()
};
// 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_ERASE_BACKGROUND (MyViewport::OnDraw)
EVT_IDLE (MyViewport::OnIdle)
END_EVENT_TABLE()
// 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)
IMPLEMENT_APP(MyApp)
// '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
frame->Show(true);
SetTopWindow(frame);
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
Refresh();
}
void MyViewport::OnDraw(wxEraseEvent& event)
{
g_pd3dDevice->BeginScene();
draw your d3d objects here
g_pd3dDevice->EndScene();
g_pd3dDevice->Present(NULL,NULL, this->GetHWND() ,NULL);
}
# by | 2007/12/17 17:45 | Development | 트랙백 | 핑백(1) | 덧글(0)
◀ 이전 페이지다음 페이지 ▶