X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=002502959ff1387e7c299697f595db62955728f6;hp=526ab6480ffd3032f3cf6c510b64deff7389ed59;hb=4f15a69a3150f180bd93fcbe1c87dbaca92a77ad;hpb=d16eb37cbc73f67fc29a60645e0b1ac7fe32767e diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index 526ab64..0025029 100644 --- a/src/graph3dview.cpp +++ b/src/graph3dview.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: graph3dview.cpp,v 1.20 2001/03/18 18:08:26 kevin Exp $ +** $Id: graph3dview.cpp,v 1.35 2003/03/23 18:37:42 kevin Exp $ ** ** 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 @@ -25,11 +25,6 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -#ifdef __GNUG__ -#pragma implementation -#pragma interface -#endif - #include "wx/wxprec.h" #ifndef WX_PRECOMP @@ -65,7 +60,7 @@ #include #endif -void +inline void Graph3dFileView::intensityToColor (double dIntensity, GLfloat* vecColor) { if (dIntensity < 0 || dIntensity > 1) { @@ -140,28 +135,21 @@ EVT_MENU(IFMENU_FILE_PROPERTIES, Graph3dFileView::OnProperties) EVT_MENU(GRAPH3D_VIEW_LIGHTING, Graph3dFileView::OnLighting) EVT_MENU(GRAPH3D_VIEW_COLOR, Graph3dFileView::OnColor) EVT_MENU(GRAPH3D_VIEW_SMOOTH, Graph3dFileView::OnSmooth) -EVT_MENU(GRAPH3D_VIEW_SURFACE, Graph3dFileView::OnSurface) +EVT_MENU(GRAPH3D_VIEW_WIREFRAME, Graph3dFileView::OnWireframe) EVT_MENU(GRAPH3D_VIEW_SCALE_MINMAX, Graph3dFileView::OnScaleSet) EVT_MENU(GRAPH3D_VIEW_SCALE_AUTO, Graph3dFileView::OnScaleAuto) EVT_MENU(GRAPH3D_VIEW_SCALE_FULL, Graph3dFileView::OnScaleFull) END_EVENT_TABLE() Graph3dFileView::Graph3dFileView () - : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pCanvas(NULL), m_pFrame(NULL) -{ - m_bDoubleBuffer = true; - m_bSmooth = true; - m_bLighting = false; - m_bSurface = false; - m_bLighting = false; - m_bColor = true; - m_dXRotate = -180; - m_dYRotate = -210; - m_dZRotate = -195; - m_bColorScaleMinSet = false; - m_bColorScaleMaxSet = false; - m_bCalculatedSurfaceBackground = false; -} + : 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_bColorScaleMinSet(false), m_bColorScaleMaxSet(false), + m_pFrame(NULL) +{} + Graph3dFileView::~Graph3dFileView() { @@ -173,39 +161,33 @@ bool Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { m_pFrame = CreateChildFrame(doc, this); - - int width, height; - m_pFrame->GetClientSize (&width, &height); - m_pFrame->SetTitle("Graph3dFileView"); + SetFrame (m_pFrame); m_pCanvas = CreateCanvas (m_pFrame); - - m_pFrame->Show (true); - m_pCanvas->SetCurrent(); - - InitGL(); - - int x, y; // X requires a forced resize - m_pFrame->GetSize(&x, &y); - m_pFrame->SetSize(-1, -1, x, y); + + m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); + m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); + m_pFrame->SetTitle("Graph3dFileView"); + + m_pCanvas->SetCurrent(); + InitGL(); + m_pCanvas->SwapBuffers(); + + m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor); + m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting); + m_pViewMenu->Check (GRAPH3D_VIEW_SMOOTH, m_bSmooth); + m_pViewMenu->Check (GRAPH3D_VIEW_WIREFRAME, m_bWireframe); + m_pFrame->SetFocus(); m_pFrame->Show(true); Activate(true); - m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor); - m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting); - m_pViewMenu->Check (GRAPH3D_VIEW_SMOOTH, m_bSmooth); - m_pViewMenu->Check (GRAPH3D_VIEW_SURFACE, m_bSurface); return true; } Graph3dFileCanvas* Graph3dFileView::CreateCanvas (wxFrame* parent) { - Graph3dFileCanvas* pCanvas; - int width, height; - parent->GetClientSize (&width, &height); - - pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(0, 0), wxSize(200, 200), 0); + Graph3dFileCanvas* pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->Clear(); @@ -241,15 +223,7 @@ Graph3dFileView::DrawSurface() glTranslated (-static_cast(nx - 1) / 2, 0.0, -static_cast(ny - 1) / 2); InitMaterials(); - if (m_bSurface) { - glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); - if (! m_bColor) { - glColor3f (1.0f, 1.0f, 1.0f); - glCallList (DISPLAYLIST_NO_COLOR); - } else - glCallList (DISPLAYLIST_COLOR); - } - else { + if (m_bWireframe) { if (! m_bColor) glColor3f (1.0f, 1.0f, 1.0f); glPolygonOffset (1.0f, 1.0f); @@ -257,10 +231,23 @@ Graph3dFileView::DrawSurface() glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); glCallList (DISPLAYLIST_COLOR); - glColor3f (0.0f, 0.0f, 0.0f); + glEnable (GL_DEPTH_TEST); + glColor3f (1.0f, 1.0f, 1.0f); glPolygonOffset (0.0f, 0.0f); glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); glCallList (DISPLAYLIST_NO_COLOR); + + } else { + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + if (! m_bColor) { + glColor3f (1.0f, 1.0f, 1.0f); + glCallList (DISPLAYLIST_NO_COLOR); + } else { + glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable (GL_COLOR_MATERIAL); + glShadeModel (GL_FLAT); + glCallList (DISPLAYLIST_COLOR); + } } } @@ -289,7 +276,8 @@ Graph3dFileView::CreateDisplayList() dYOffset = 0; double dXPos = -dXOffset; - for (unsigned ix = 0; ix < nx - 1; ix++, dXPos++) { + unsigned int ix; + for (ix = 0; ix < nx - 1; ix++, dXPos++) { double dYPos = -dYOffset; glBegin(GL_QUAD_STRIP); double p1[3], p2[3], p3[3], n1[3]; @@ -298,7 +286,7 @@ Graph3dFileView::CreateDisplayList() p3[0] = dXPos; p3[1] = actScale * (v[ix][1] + actOffset); p3[2] = dYPos + 1; CalculateVectorNormal (p1, p2, p3, &n1[0], &n1[1], &n1[2]); - double dIntensity1, dIntensity2; + double dIntensity1 = 0., dIntensity2 = 0.; if (m_bColor) { dIntensity1 = (v[ix][0] - dMin) / dIntensityScale; dIntensity2 = (v[ix+1][0] - dMin) / dIntensityScale; @@ -308,12 +296,13 @@ Graph3dFileView::CreateDisplayList() intensityToColor (dIntensity1, vecColor); glColor3fv (vecColor); } - glVertex3dv (p1); - glNormal3dv (n1); + glVertex3dv (p1); glNormal3dv (n1); + if (m_bColor) { intensityToColor (dIntensity2, vecColor); glColor3fv (vecColor); - glVertex3dv (p2); - glNormal3dv (n1); + } + glVertex3dv (p2); glNormal3dv (n1); + double lastP[3]; lastP[0] = ix; lastP[1] = actScale * (v[ix][0] + actOffset); lastP[2] = 0; for (unsigned int iy = 1; iy < ny - 1; iy++, dYPos++) { @@ -321,14 +310,18 @@ Graph3dFileView::CreateDisplayList() p2[0] = dXPos+1; p2[1] = actScale * (v[ix+1][iy] + actOffset); p2[2] = dYPos; CalculateVectorNormal (p1, p2, lastP, &n1[0], &n1[1], &n1[2]); lastP[0] = p1[0]; lastP[1] = p1[1]; lastP[2] = p1[2]; - dIntensity1 = (v[ix][iy] - dMin) / dIntensityScale; - dIntensity2 = (v[ix+1][iy] - dMin) / dIntensityScale; - intensityToColor (dIntensity1, vecColor); - glColor3fv (vecColor); - glVertex3dv (p1); glNormal3dv (n1); - intensityToColor (dIntensity2, vecColor); - glColor3fv (vecColor); - glVertex3dv (p2); glNormal3dv (n1); + if (m_bColor) { + dIntensity1 = (v[ix][iy] - dMin) / dIntensityScale; + dIntensity2 = (v[ix+1][iy] - dMin) / dIntensityScale; + intensityToColor (dIntensity1, vecColor); + glColor3fv (vecColor); + } + glVertex3dv (p1); glNormal3dv (n1); + if (m_bColor) { + intensityToColor (dIntensity2, vecColor); + glColor3fv (vecColor); + } + glVertex3dv (p2); glNormal3dv (n1); } glEnd(); // QUAD_STRIP } @@ -355,7 +348,7 @@ Graph3dFileView::CreateDisplayList() for (unsigned int iy = 1; iy < ny - 1; iy++, dYPos++) { p1[0] = dXPos; p1[1] = actScale * (v[ix][iy] + actOffset); p1[2] = dYPos; p2[0] = dXPos+1; p2[1] = actScale * (v[ix+1][iy] + actOffset); p2[2] = dYPos; - CalculateVectorNormal (p1, p2, lastP, &n1[0], &n1[1], &n1[2]); + CalculateVectorNormal (p1, p2, lastP, &n1[0], &n1[1], &n1[2]); lastP[0] = p1[0]; lastP[1] = p1[1]; lastP[2] = p1[2]; glVertex3dv (p1); glNormal3dv (n1); glVertex3dv (p2); glNormal3dv (n1); @@ -366,19 +359,13 @@ Graph3dFileView::CreateDisplayList() } -void -Graph3dFileView::calculateSurfaceBackground () -{ - if (m_bCalculatedSurfaceBackground) - return; -} - void Graph3dFileView::OnProperties (wxCommandEvent& event) { std::ostringstream os; *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n"; - wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION); + wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), + "Imagefile Properties", wxOK | wxICON_INFORMATION); dialogMsg.ShowModal(); } @@ -387,15 +374,14 @@ Graph3dFileView::OnLighting (wxCommandEvent& event) { m_bLighting = ! m_bLighting; m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting); - m_pCanvas->Refresh(); } void -Graph3dFileView::OnSurface (wxCommandEvent& event) +Graph3dFileView::OnWireframe (wxCommandEvent& event) { - m_bSurface = ! m_bSurface; - m_pViewMenu->Check (GRAPH3D_VIEW_SURFACE, m_bSurface); + m_bWireframe = ! m_bWireframe; + m_pViewMenu->Check (GRAPH3D_VIEW_WIREFRAME, m_bWireframe); m_pCanvas->Refresh(); } @@ -420,19 +406,21 @@ Graph3dFileView::OnSmooth (wxCommandEvent& event) void Graph3dFileView::OnDraw (wxDC* dc) { - if (! m_pCanvas) - return; - m_pCanvas->SetCurrent(); - -#ifndef __WXMOTIF__ - // if (! m_pCanvas->GetContext()) return; + if (m_pCanvas) { + m_pCanvas->SetCurrent(); +#ifdef DEBUG + *theApp->getLog() << "Drawing 3d surface\n"; #endif - - Draw(); - std::ostringstream os; - os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate << ", Zangle=" << m_dZRotate; - m_pStatusBar->SetStatusText (os.str().c_str()); - m_pCanvas->SwapBuffers(); + Draw(); + m_pCanvas->SwapBuffers(); + } + + if (m_pStatusBar) { + std::ostringstream os; + os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate + << ", Zangle=" << m_dZRotate; + m_pStatusBar->SetStatusText (os.str().c_str()); + } } @@ -456,31 +444,29 @@ Graph3dFileView::InitMaterials() int ny = GetDocument()->ny(); #if 1 - static float ambient[] = {0.1f, 0.1f, 0.1f, 1.0f}; - static float diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; - static float position0[] = {-nx/2, -ny/2, ny/2, 0.0f, 0.0f}; - static float position1[] = {-nx/2, -ny/2, -ny/2, 0.0f}; - static float ambient1[] = {0.5f, 0.5f, 0.5f, 1.0f}; + static float position0[] = {nx/2, ny*2, -ny*2, 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 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}; // static float position1[] = {0.0f, 0.0f, -20.0f, 0.0f}; - static float front_mat_shininess[] = {5.0f}; - static float front_mat_specular[] = {0.1f, 0.1f, 0.1f, 1.0f}; + static float front_mat_shininess[] = {60.0f}; + static float front_mat_specular[] = {0.2f, 0.2f, 0.2f, 1.0f}; static float front_mat_diffuse[] = {0.3f, 0.3f, 0.3f, 1.0f}; - /* - static float back_mat_shininess[] = {60.0f}; - static float back_mat_specular[] = {0.2f, 0.2f, 0.2f, 1.0f}; + static float back_mat_shininess[] = {10.0f}; + static float back_mat_specular[] = {0.1f, 0.1f, 0.1f, 1.0f}; static float back_mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; - */ static float lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f}; - static float lmodel_twoside[] = {GL_FALSE}; + static float lmodel_twoside[] = {GL_TRUE}; - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH, GL_DONT_CARE); glEnable(GL_NORMALIZE); - glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); - glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv (GL_LIGHT0, GL_AMBIENT, ambient0); + glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightfv (GL_LIGHT0, GL_POSITION, position0); glEnable (GL_LIGHT0); @@ -495,9 +481,12 @@ Graph3dFileView::InitMaterials() glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv (GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv (GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv (GL_BACK, GL_DIFFUSE, back_mat_diffuse); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); - // glColorMaterial (GL_FRONT_AND_BACK, GL_SPECULAR); + glColorMaterial (GL_FRONT_AND_BACK, GL_SPECULAR); glEnable(GL_COLOR_MATERIAL); #else GLfloat impLPos[] = {1.0f, 1.0f, 1.0f, 0.0f}; @@ -625,6 +614,10 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) m_dColorScaleMax = max; } double dRadius = maxValue (nx, ny) * SQRT2 / 2; + + if (m_pCanvas) + m_pCanvas->SetCurrent(); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (-dRadius, dRadius, -dRadius, dRadius, dRadius*5, -dRadius*5); @@ -640,9 +633,11 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) #endif CreateDisplayList(); - - if (m_pCanvas) + + if (m_pCanvas) { + m_pCanvas->SwapBuffers(); m_pCanvas->Refresh(); + } } bool @@ -665,11 +660,25 @@ Graph3dFileView::OnClose (bool deleteWindow) if (deleteWindow) { delete m_pFrame; m_pFrame = NULL; + if (GetDocument() && GetDocument()->getBadFileOpen()) + ::wxYield(); // wxWindows bug workaround } return true; } +void +Graph3dFileView::setInitialClientSize () +{ + if (m_pFrame && m_pCanvas) { + wxSize bestSize = m_pCanvas->GetBestSize(); + + m_pFrame->SetClientSize (bestSize); + m_pFrame->Show (true); + m_pFrame->SetFocus(); + } +} + void Graph3dFileView::OnScaleAuto (wxCommandEvent& event) { @@ -702,7 +711,7 @@ Graph3dFileView::OnScaleSet (wxCommandEvent& event) unsigned int nx = GetDocument()->nx(); unsigned int ny = GetDocument()->ny(); const ImageFileArrayConst v = GetDocument()->getArray(); - double dMin, dMax; + double dMin = 0., dMax = 0.; if (! m_bColorScaleMinSet && ! m_bColorScaleMaxSet) { dMax = dMin = v[0][0]; for (unsigned ix = 0; ix < nx; ix++) @@ -746,15 +755,19 @@ wxDocChildFrame* Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) { #if CTSIM_MDI - wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #else - wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #endif theApp->setIconForFrame (subframe); +// status bar text not showing tested with enlightenment. disabling for now... +#if 0 m_pStatusBar = new wxStatusBar (subframe, -1); subframe->SetStatusBar (m_pStatusBar); - + m_pStatusBar->Show(true); +#endif + m_pFileMenu = new wxMenu; m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P"); @@ -769,15 +782,15 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) m_pFileMenu->Append(wxID_PRINT, "&Print..."); m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup..."); m_pFileMenu->Append(wxID_PREVIEW, "Print Preview"); -#ifdef CTSIM_MDI m_pFileMenu->AppendSeparator(); + m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces..."); m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif + GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); m_pViewMenu = new wxMenu; - m_pViewMenu->Append(GRAPH3D_VIEW_SURFACE, "Su&rface\tCtrl-R", "", true); + m_pViewMenu->Append(GRAPH3D_VIEW_WIREFRAME, "Wi&reframe\tCtrl-R", "", true); m_pViewMenu->Append(GRAPH3D_VIEW_SMOOTH, "S&mooth\tCtrl-M", "", true); m_pViewMenu->Append(GRAPH3D_VIEW_COLOR, "Co&lor\tCtrl-L", "", true); m_pViewMenu->Append(GRAPH3D_VIEW_LIGHTING, "Li&ghting\tCtrl-G", "", true); @@ -802,7 +815,7 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) subframe->Centre(wxBOTH); wxAcceleratorEntry accelEntries[7]; - accelEntries[0].Set (wxACCEL_CTRL, static_cast('R'), GRAPH3D_VIEW_SURFACE); + accelEntries[0].Set (wxACCEL_CTRL, static_cast('R'), GRAPH3D_VIEW_WIREFRAME); accelEntries[1].Set (wxACCEL_CTRL, static_cast('L'), GRAPH3D_VIEW_COLOR); accelEntries[2].Set (wxACCEL_CTRL, static_cast('G'), GRAPH3D_VIEW_LIGHTING); accelEntries[3].Set (wxACCEL_CTRL, static_cast('M'), GRAPH3D_VIEW_SMOOTH); @@ -817,9 +830,10 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) + BEGIN_EVENT_TABLE(Graph3dFileCanvas, wxGLCanvas) -EVT_SIZE(Graph3dFileCanvas::OnSize) EVT_PAINT(Graph3dFileCanvas::OnPaint) +EVT_SIZE(Graph3dFileCanvas::OnSize) EVT_CHAR(Graph3dFileCanvas::OnChar) EVT_MOUSE_EVENTS(Graph3dFileCanvas::OnMouseEvent) EVT_ERASE_BACKGROUND(Graph3dFileCanvas::OnEraseBackground) @@ -827,14 +841,11 @@ END_EVENT_TABLE() - Graph3dFileCanvas::Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos, - const wxSize& size, long style): -wxGLCanvas (parent, -1, pos, size, style, _T("Graph3dCanvas") - ), m_pView(view) + const wxSize& size, long style) + : wxGLCanvas (parent, -1, pos, size, style), m_pView(view) { - parent->Show (true); - SetCurrent(); +// parent->Show (true); #if 0 // Make sure server supports the vertex array extension char* extensions = (char *) glGetString( GL_EXTENSIONS ); @@ -850,20 +861,27 @@ Graph3dFileCanvas::~Graph3dFileCanvas() } void -Graph3dFileCanvas::OnDraw (wxDC& dc) +Graph3dFileCanvas::OnPaint (wxPaintEvent& event) { + wxPaintDC dc(this); if (m_pView) m_pView->OnDraw(& dc); } + +wxSize +Graph3dFileCanvas::GetBestSize() const +{ + return wxSize (400,400); +} + void Graph3dFileCanvas::OnSize (wxSizeEvent& event) { #ifndef __WXMOTIF__ - if (!GetContext()) return; + // if (!GetContext()) return; #endif - SetCurrent(); int width, height; GetClientSize (&width, &height); Reshape (width, height); @@ -901,8 +919,8 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event) m_pView->m_dYRotate -= 15.0; Refresh (false); break; - case 'r': case 'R': - m_pView->OnSurface (dummyEvent); + case 'w': case 'W': + m_pView->OnWireframe (dummyEvent); break; case 's': case 'S': m_pView->OnSmooth (dummyEvent); @@ -922,7 +940,9 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event) void Graph3dFileCanvas::Reshape (int width, int height) { + SetCurrent(); glViewport (0, 0, (GLint)width, (GLint)height); + SwapBuffers(); }