fix the loading of the isosurf data; it was not loaded correctly on my system because isosurf.dat uses dots as decimal separators and my locale requires commas; fixed instancing a wxLocale with wxLANGUAGE_ENGLISH)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57335 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-12-14 16:13:29 +00:00
parent d5c8403a37
commit 0c1c1c714a
2 changed files with 37 additions and 54 deletions

View File

@@ -2,7 +2,7 @@
// Name: isosurf.cpp // Name: isosurf.cpp
// Purpose: wxGLCanvas demo program // Purpose: wxGLCanvas demo program
// Author: Brian Paul (original gltk version), Wolfram Gloger // Author: Brian Paul (original gltk version), Wolfram Gloger
// Modified by: Julian Smart // Modified by: Julian Smart, Francesco Montorsi
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart
@@ -29,9 +29,9 @@
#include "wx/math.h" #include "wx/math.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/cmdline.h" #include "wx/cmdline.h"
#include "wx/archive.h"
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/zstream.h" #include "wx/zstream.h"
#include "wx/txtstrm.h"
#include "isosurf.h" #include "isosurf.h"
#include "../../sample.xpm" #include "../../sample.xpm"
@@ -58,8 +58,7 @@ bool MyApp::OnInit()
return false; return false;
// Create the main frame window // Create the main frame window
SetTopWindow(new MyFrame(NULL, wxT("wxWidgets OpenGL Isosurf Sample"), SetTopWindow(new MyFrame(NULL, wxT("wxWidgets OpenGL Isosurf Sample")));
wxDefaultPosition, wxDefaultSize));
return true; return true;
} }
@@ -131,7 +130,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
if (!g_doubleBuffer) if (!g_doubleBuffer)
{ {
wxLogWarning("don't have double buffer, disabling\n"); wxLogWarning("Disabling double buffering");
#ifdef __WXGTK__ #ifdef __WXGTK__
gl_attrib[9] = None; gl_attrib[9] = None;
@@ -142,8 +141,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
// Show the frame // Show the frame
Show(true); Show(true);
m_canvas = new TestGLCanvas(this, wxID_ANY, wxDefaultPosition, m_canvas = new TestGLCanvas(this, wxID_ANY, gl_attrib);
GetClientSize(), 0, _T("TestGLCanvas"), gl_attrib);
} }
MyFrame::~MyFrame() MyFrame::~MyFrame()
@@ -172,14 +170,13 @@ END_EVENT_TABLE()
TestGLCanvas::TestGLCanvas(wxWindow *parent, TestGLCanvas::TestGLCanvas(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name,
int* gl_attrib) int* gl_attrib)
: wxGLCanvas(parent, id, gl_attrib, pos, size, : wxGLCanvas(parent, id, gl_attrib)
style | wxFULL_REPAINT_ON_RESIZE, name)
{ {
m_xrot = 0;
m_yrot = 0;
m_numverts = 0;
// Explicitly create a new rendering context instance for this canvas. // Explicitly create a new rendering context instance for this canvas.
m_glRC = new wxGLContext(this); m_glRC = new wxGLContext(this);
@@ -198,6 +195,12 @@ TestGLCanvas::~TestGLCanvas()
void TestGLCanvas::LoadSurface(const wxString& filename) void TestGLCanvas::LoadSurface(const wxString& filename)
{ {
// FIXME
// we need to set english locale to force wxTextInputStream's calls to
// wxStrtod to use the point and not the comma as decimal separator...
// (the isosurf.dat contains points and not commas)...
wxLocale l(wxLANGUAGE_ENGLISH);
wxZlibInputStream* stream = wxZlibInputStream* stream =
new wxZlibInputStream(new wxFFileInputStream(filename)); new wxZlibInputStream(new wxFFileInputStream(filename));
if (!stream || !stream->IsOk()) if (!stream || !stream->IsOk())
@@ -207,34 +210,26 @@ void TestGLCanvas::LoadSurface(const wxString& filename)
return; return;
} }
{
// we suppose to have in input a text file containing floating numbers
// space/newline-separed... first 3 numbers are the coordinates of a
// vertex and the following 3 are the relative vertex normal and so on...
wxTextInputStream inFile(*stream);
m_numverts = 0; m_numverts = 0;
const size_t sz = sizeof(GLfloat); while (!stream->Eof() && m_numverts < MAXVERTS)// && m_numverts<MAXVERTS)
while (!stream->Eof() && m_numverts < MAXVERTS)
{ {
// read a vertex inFile >> m_verts[m_numverts][0] >> m_verts[m_numverts][1] >> m_verts[m_numverts][2];
for (int i=0; i<3; i++) inFile >> m_norms[m_numverts][0] >> m_norms[m_numverts][1] >> m_norms[m_numverts][2];
if (stream->Read(&m_verts[m_numverts][i], sz).LastRead() != sz)
{
wxLogError("Cannot read the %d-th vertex in '%s'!",
m_numverts, filename.c_str());
delete stream;
return;
}
// read its normal
for (int i=0; i<3; i++)
if (stream->Read(&m_norms[m_numverts][i], sz).LastRead() != sz)
{
wxLogError("Cannot read the %d-th vertex in '%s'!",
m_numverts, filename.c_str());
delete stream;
return;
}
m_numverts++; m_numverts++;
} }
// discard last vertex; it is a zero caused by the EOF
m_numverts--;
}
delete stream; delete stream;
wxLogMessage(_T("Loaded %d vertices, %d triangles from '%s'"), wxLogMessage(_T("Loaded %d vertices, %d triangles from '%s'"),
@@ -257,11 +252,11 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
glRotatef( m_xrot, 1.0f, 0.0f, 0.0f ); glRotatef( m_xrot, 1.0f, 0.0f, 0.0f );
// draw the surface // draw the surface
/* if (g_use_vertex_arrays) if (g_use_vertex_arrays)
{ {
glDrawArrays( GL_TRIANGLE_STRIP, 0, m_numverts ); glDrawArrays( GL_TRIANGLE_STRIP, 0, m_numverts );
} }
else*/ else
{ {
glBegin( GL_TRIANGLE_STRIP ); glBegin( GL_TRIANGLE_STRIP );
@@ -320,25 +315,17 @@ void TestGLCanvas::OnChar(wxKeyEvent& event)
case 's': case 'S': case 's': case 'S':
g_smooth = !g_smooth; g_smooth = !g_smooth;
if (g_smooth) if (g_smooth)
{
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
}
else else
{
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
}
break; break;
case 'l': case 'L': case 'l': case 'L':
g_lighting = !g_lighting; g_lighting = !g_lighting;
if (g_lighting) if (g_lighting)
{
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
}
else else
{
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
}
break; break;
default: default:
@@ -436,8 +423,8 @@ void TestGLCanvas::InitGL()
{ {
glVertexPointer( 3, GL_FLOAT, 0, m_verts ); glVertexPointer( 3, GL_FLOAT, 0, m_verts );
glNormalPointer( GL_FLOAT, 0, m_norms ); glNormalPointer( GL_FLOAT, 0, m_norms );
glEnable( GL_VERTEX_ARRAY_EXT ); glEnable( GL_VERTEX_ARRAY );
glEnable( GL_NORMAL_ARRAY_EXT ); glEnable( GL_NORMAL_ARRAY );
} }
} }

View File

@@ -47,10 +47,6 @@ class TestGLCanvas : public wxGLCanvas
public: public:
TestGLCanvas(wxWindow *parent, TestGLCanvas(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = _T("TestGLCanvas"),
int *gl_attrib = NULL); int *gl_attrib = NULL);
virtual ~TestGLCanvas(); virtual ~TestGLCanvas();
@@ -85,8 +81,8 @@ class MyFrame : public wxFrame
public: public:
MyFrame(wxFrame *frame, MyFrame(wxFrame *frame,
const wxString& title, const wxString& title,
const wxPoint& pos, const wxPoint& pos = wxDefaultPosition,
const wxSize& size, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE); long style = wxDEFAULT_FRAME_STYLE);
virtual ~MyFrame(); virtual ~MyFrame();