update the samples to use new (non-deprecated) wxGLCanvas API; added more comments; some cleanup (modified patch 1882679)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51630 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "dxfrenderer.h"
|
||||
|
||||
#include "wx/listimpl.cpp"
|
||||
@@ -435,6 +437,22 @@ bool DXFRenderer::ParseTables(wxInputStream& stream)
|
||||
return false;
|
||||
}
|
||||
|
||||
// This method is used instead of numStr.ToDouble(d) because the latter
|
||||
// (wxString::ToDouble()) takes the systems proper locale into account,
|
||||
// whereas the implementation below works with the default locale.
|
||||
// (Converting numbers that are formatted in the default locale can fail
|
||||
// with system locales that use e.g. the comma as the decimal separator.)
|
||||
static double ToDouble(const wxString& numStr)
|
||||
{
|
||||
double d;
|
||||
std::string numStr_(numStr.c_str());
|
||||
std::istringstream iss(numStr_);
|
||||
|
||||
iss >> d;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// parse entities section: save 3DFACE and LINE entities
|
||||
bool DXFRenderer::ParseEntities(wxInputStream& stream)
|
||||
{
|
||||
@@ -490,8 +508,8 @@ bool DXFRenderer::ParseEntities(wxInputStream& stream)
|
||||
state = 2;
|
||||
else if (state > 0)
|
||||
{
|
||||
double d;
|
||||
line2.ToDouble(&d);
|
||||
const double d=ToDouble(line2);
|
||||
|
||||
if (line1 == wxT("10"))
|
||||
v[0].x = d;
|
||||
else if (line1 == wxT("20"))
|
||||
|
@@ -94,8 +94,10 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
menuBar->Append(helpMenu, wxT("&Help"));
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
Show(true);
|
||||
|
||||
m_canvas = new TestGLCanvas(this, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(300, 300), wxSUNKEN_BORDER);
|
||||
GetClientSize(), wxSUNKEN_BORDER);
|
||||
}
|
||||
|
||||
// File|Open... command
|
||||
@@ -139,10 +141,21 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||
EVT_MOUSE_EVENTS(TestGLCanvas::OnMouse)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
: wxGLCanvas(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE, name)
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxString& name)
|
||||
: wxGLCanvas(parent, id, NULL, pos, size,
|
||||
style | wxFULL_REPAINT_ON_RESIZE, name)
|
||||
{
|
||||
// Explicitly create a new rendering context instance for this canvas.
|
||||
m_glRC = new wxGLContext(this);
|
||||
|
||||
// Make the new context current (activate it for use) with this canvas.
|
||||
SetCurrent(*m_glRC);
|
||||
|
||||
m_gldata.initialized = false;
|
||||
|
||||
// initialize view matrix
|
||||
@@ -154,6 +167,7 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||
|
||||
TestGLCanvas::~TestGLCanvas()
|
||||
{
|
||||
delete m_glRC;
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
||||
@@ -161,11 +175,7 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
||||
// must always be here
|
||||
wxPaintDC dc(this);
|
||||
|
||||
#ifndef __WXMOTIF__
|
||||
if (!GetContext()) return;
|
||||
#endif
|
||||
|
||||
SetCurrent();
|
||||
SetCurrent(*m_glRC);
|
||||
|
||||
// Initialize OpenGL
|
||||
if (!m_gldata.initialized)
|
||||
@@ -195,11 +205,11 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||
void TestGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
|
||||
{
|
||||
// this is also necessary to update the context on some platforms
|
||||
wxGLCanvas::OnSize(event);
|
||||
// Reset the OpenGL view aspect
|
||||
// Reset the OpenGL view aspect.
|
||||
// This is OK only because there is only one canvas that uses the context.
|
||||
// See the cube sample for that case that multiple canvases are made current with one context.
|
||||
ResetProjectionMode();
|
||||
}
|
||||
|
||||
@@ -293,18 +303,21 @@ void TestGLCanvas::InitGL()
|
||||
|
||||
void TestGLCanvas::ResetProjectionMode()
|
||||
{
|
||||
// This is normally only necessary if there is more than one wxGLCanvas
|
||||
// or more than one wxGLContext in the application.
|
||||
SetCurrent(*m_glRC);
|
||||
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
#ifndef __WXMOTIF__
|
||||
if ( GetContext() )
|
||||
#endif
|
||||
{
|
||||
SetCurrent();
|
||||
glViewport(0, 0, (GLint) w, (GLint) h);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (GLfloat)w/h, 1.0, 100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
// It's up to the application code to update the OpenGL viewport settings.
|
||||
// In order to avoid extensive context switching, consider doing this in
|
||||
// OnPaint() rather than here, though.
|
||||
glViewport(0, 0, (GLint) w, (GLint) h);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (GLfloat)w/h, 1.0, 100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ extern "C"
|
||||
|
||||
#include "dxfrenderer.h"
|
||||
|
||||
|
||||
// OpenGL view data
|
||||
struct GLData
|
||||
{
|
||||
@@ -40,40 +41,40 @@ struct GLData
|
||||
float zoom; // field of view in degrees
|
||||
};
|
||||
|
||||
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
class MyApp : public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit();
|
||||
virtual bool OnInit();
|
||||
};
|
||||
|
||||
|
||||
// Define a new frame type
|
||||
class TestGLCanvas;
|
||||
|
||||
class MyFrame: public wxFrame
|
||||
|
||||
class MyFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
||||
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
void OnMenuFileOpen(wxCommandEvent& event);
|
||||
void OnMenuFileExit(wxCommandEvent& event);
|
||||
void OnMenuHelpAbout(wxCommandEvent& event);
|
||||
|
||||
#if wxUSE_GLCANVAS
|
||||
void SetCanvas( TestGLCanvas *canvas ) { m_canvas = canvas; }
|
||||
void SetCanvas(TestGLCanvas *canvas) { m_canvas = canvas; }
|
||||
TestGLCanvas *GetCanvas() { return m_canvas; }
|
||||
|
||||
private:
|
||||
TestGLCanvas *m_canvas;
|
||||
#endif
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#if wxUSE_GLCANVAS
|
||||
|
||||
class TestGLCanvas: public wxGLCanvas
|
||||
class TestGLCanvas : public wxGLCanvas
|
||||
{
|
||||
public:
|
||||
TestGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
|
||||
@@ -81,7 +82,7 @@ public:
|
||||
const wxSize& size = wxDefaultSize, long style = 0,
|
||||
const wxString& name = wxT("TestGLCanvas"));
|
||||
|
||||
~TestGLCanvas();
|
||||
virtual ~TestGLCanvas();
|
||||
|
||||
void LoadDXF(const wxString& filename);
|
||||
|
||||
@@ -95,13 +96,12 @@ private:
|
||||
void InitGL();
|
||||
void ResetProjectionMode();
|
||||
|
||||
GLData m_gldata;
|
||||
DXFRenderer m_renderer;
|
||||
wxGLContext* m_glRC;
|
||||
GLData m_gldata;
|
||||
DXFRenderer m_renderer;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(TestGLCanvas)
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#endif // #if wxUSE_GLCANVAS
|
||||
|
||||
#endif // #ifndef _WX_PENGUIN_H_
|
||||
|
||||
|
Reference in New Issue
Block a user