X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=ee5147f4dc9e54e8caf9f14387a2c15d09302261;hp=747e983d39a419e20282f0055cdcaad92191a4f9;hb=e8462f7431582627e44906239077f1c696eefba1;hpb=f7ee98f7d964ed361068179f0e7ea4475ed1abdf diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index 747e983..ee5147f 100644 --- a/src/graph3dview.cpp +++ b/src/graph3dview.cpp @@ -7,9 +7,7 @@ ** Date Started: Jan 2001 ** ** This is part of the CTSim program -** Copyright (c) 1983-2001 Kevin Rosenberg -** -** $Id$ +** Copyright (c) 1983-2009 Kevin Rosenberg ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -145,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) {} @@ -155,6 +153,8 @@ Graph3dFileView::~Graph3dFileView() { GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu); GetDocumentManager()->ActivateView(this, false); + if (m_pGLContext) + delete m_pGLContext; } bool @@ -162,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); @@ -181,13 +172,28 @@ 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; } Graph3dFileCanvas* Graph3dFileView::CreateCanvas (wxFrame* parent) { - Graph3dFileCanvas* pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0); + Graph3dFileCanvas* pCanvas = + new Graph3dFileCanvas (this, parent, NULL, + wxDefaultPosition, wxDefaultSize, + wxFULL_REPAINT_ON_RESIZE); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->ClearBackground(); @@ -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 @@ -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(); }