X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=37a3dede7adf32c04d014802e3621ba2bcf20d0a;hp=d694b32504af56f429ea2fbe05e214e02a99fe7b;hb=9ac3b88884957e2c07bf365c2503c6c1fbeaa60e;hpb=a15586dedc133281ecca0cc682fe4dd5eb1fceb1 diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index d694b32..37a3ded 100644 --- a/src/graph3dview.cpp +++ b/src/graph3dview.cpp @@ -143,9 +143,9 @@ Graph3dFileView::Graph3dFileView () : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pStatusBar(NULL), m_pCanvas(NULL), m_dXRotate(-180), m_dYRotate(-210), m_dZRotate(195), m_bDoubleBuffer(true), m_bSmooth(true), m_bWireframe(false), - m_bLighting(false), m_bColor(true), m_bUseVertexArrays(false), + m_bLighting(false), m_bColor(true), m_bColorScaleMinSet(false), m_bColorScaleMaxSet(false), - m_pFrame(NULL) + m_pGLContext(NULL), m_pFrame(NULL) {} @@ -153,6 +153,8 @@ Graph3dFileView::~Graph3dFileView() { GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu); GetDocumentManager()->ActivateView(this, false); + if (m_pGLContext) + delete m_pGLContext; } bool @@ -160,15 +162,6 @@ Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { m_pFrame = CreateChildFrame(doc, this); SetFrame (m_pFrame); - m_pCanvas = CreateCanvas (m_pFrame); - - m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); - m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); - m_pFrame->SetTitle(_T("Graph3dFileView")); - - m_pCanvas->SetCurrent(); - InitGL(); - m_pCanvas->SwapBuffers(); m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor); m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting); @@ -179,6 +172,18 @@ Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) m_pFrame->Show(true); Activate(true); +#if 1 + m_pCanvas = CreateCanvas (m_pFrame); + m_pGLContext = new wxGLContext (m_pCanvas); + m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); + m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); + m_pFrame->SetTitle(doc->GetFilename()); + + m_pCanvas->SetCurrent(*m_pGLContext); + InitGL(); // Crash + m_pCanvas->SwapBuffers(); +#endif + return true; } @@ -186,7 +191,8 @@ Graph3dFileCanvas* Graph3dFileView::CreateCanvas (wxFrame* parent) { Graph3dFileCanvas* pCanvas = - new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), + new Graph3dFileCanvas (this, parent, NULL, + wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE); pCanvas->SetBackgroundColour(*wxWHITE); @@ -408,7 +414,7 @@ void Graph3dFileView::OnDraw (wxDC* dc) { if (m_pCanvas) { - m_pCanvas->SetCurrent(); + m_pCanvas->SetCurrent(*m_pGLContext); #ifdef DEBUG *theApp->getLog() << _T("Drawing 3d surface\n"); #endif @@ -445,10 +451,10 @@ Graph3dFileView::InitMaterials() int ny = GetDocument()->ny(); #if 1 - static float position0[] = {nx/2, ny*2, -ny*2, 0.0f,}; + static float position0[] = {nx/2.0f, ny*2.0f, -ny*2.0f, 0.0f,}; static float ambient0[] = {.1f, .1f, .1f, 1.0f}; static float diffuse0[] = {1.0f, 1.0f, 1.0f, 1.0f}; - static float position1[] = {-nx/2, -ny*2, -ny*2, 0.0f,}; + static float position1[] = {-nx/2.0f, -ny*2.0f, -ny*2.0f, 0.0f,}; static float ambient1[] = {.1f, .1f, .1f, .1f}; static float diffuse1[] = {1.0f, 1.0f, 1.0f, 1.0f}; // static float position0[] = {0.0f, 0.0f, 20.0f, 0.0f}; @@ -599,7 +605,7 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) if (v != NULL && nx != 0 && ny != 0) { double min = v[0][0]; double max = min; - for (unsigned int ix = 0; ix < nx; ix++) + for (unsigned int ix = 0; ix < nx; ix++) { for (unsigned int iy = 0; iy < ny; iy++) { double dVal = v[ix][iy]; if (min > dVal) @@ -607,17 +613,18 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) else if (max < dVal) max = dVal; } - m_dGraphMin = min; - m_dGraphMax = max; - if (! m_bColorScaleMinSet) - m_dColorScaleMin = min; - if (! m_bColorScaleMaxSet) - m_dColorScaleMax = max; + } + m_dGraphMin = min; + m_dGraphMax = max; + if (! m_bColorScaleMinSet) + m_dColorScaleMin = min; + if (! m_bColorScaleMaxSet) + m_dColorScaleMax = max; } double dRadius = maxValue (nx, ny) * SQRT2 / 2; if (m_pCanvas) - m_pCanvas->SetCurrent(); + m_pCanvas->SetCurrent(*m_pGLContext); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -841,19 +848,12 @@ EVT_ERASE_BACKGROUND(Graph3dFileCanvas::OnEraseBackground) END_EVENT_TABLE() - -Graph3dFileCanvas::Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos, +Graph3dFileCanvas::Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, + int* attribList, + const wxPoint& pos, const wxSize& size, long style) - : wxGLCanvas (parent, -1, pos, size, style), m_pView(view) +: wxGLCanvas (parent, wxID_ANY, attribList, pos, size, style), m_pView(view) { -// parent->Show (true); -#if 0 - // Make sure server supports the vertex array extension - char* extensions = (char *) glGetString( GL_EXTENSIONS ); - if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" )) { - m_pView->m_bUseVertexArrays = GL_FALSE; - } -#endif } @@ -885,7 +885,7 @@ Graph3dFileCanvas::OnSize (wxSizeEvent& event) int width, height; GetClientSize (&width, &height); - Reshape (width, height); + Reshape (width, height); // Crash } void @@ -941,7 +941,7 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event) void Graph3dFileCanvas::Reshape (int width, int height) { - SetCurrent(); + SetCurrent(*m_pView->m_pGLContext); glViewport (0, 0, (GLint)width, (GLint)height); SwapBuffers(); }