does someone knows if there is a problem/bug when combining the doc/view architecture and the STL? I did the classical "doodles" example using openGL instead of the traditional device context approach:
Code: Select all
/******************************************************************************/
void Canvas::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
SetCurrent();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
if(m_View)
m_View->OnDraw(&dc);
glPopMatrix();
SwapBuffers();
}
/******************************************************************************/
Code: Select all
/******************************************************************************/
void GraphicsView::OnDraw(wxDC *dc)
{
GraphicsDoc *doc=(GraphicsDoc *)GetDocument();
std::list<Shape *>::const_iterator pos;
for(pos=doc->m_Shapes.begin();pos!=doc->m_Shapes.end();++pos) //code crashes somewhere around here
(*pos)->Draw();
}
/******************************************************************************/
I had so strange problems (if I changed the container to a vector then everything was fine for example) that I decided to go back to the primitive "frame" architecture I'm used to:
Code: Select all
/******************************************************************************/
void Canvas::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
SetCurrent();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
std::list<Shape *>::const_iterator pos;
for(pos=m_Shapes.begin();pos!=m_Shapes.end();++pos)
(*pos)->Draw();
glPopMatrix();
SwapBuffers();
}
/******************************************************************************/
Thanks,
Sergio
P.D: why doesn't dynamic_cast work properly and instead the unsafer C downcasting system works fine? I mean:
Code: Select all
/******************************************************************************/
Canvas::Canvas(wxWindow *parent, wxWindowID id,const wxPoint& pos, const wxSize& size)
: wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size)
{
m_Frame = (GraphicsFrame *)parent; //dynamic_cast<GraphicsFrame> *(parent) makes this crash!!!
SetCurrent();
glClearColor(0.5,0.5,0.5,0.0);
glOrtho(-10.0,10.0,-10.0,10.0,-10.0,10.0);
}
/******************************************************************************/