X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/451c13c85ce4338db0853cfc1f148f8c92eaf91c..d02852036df240b17f3164a940383502829435a4:/samples/opengl/isosurf/isosurf.cpp diff --git a/samples/opengl/isosurf/isosurf.cpp b/samples/opengl/isosurf/isosurf.cpp index f89ba3f71f..fb8039efa7 100644 --- a/samples/opengl/isosurf/isosurf.cpp +++ b/samples/opengl/isosurf/isosurf.cpp @@ -2,7 +2,7 @@ // Name: isosurf.cpp // Purpose: wxGLCanvas demo program // Author: Brian Paul (original gltk version), Wolfram Gloger -// Modified by: Julian Smart +// Modified by: Julian Smart, Francesco Montorsi // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart @@ -27,232 +27,67 @@ #include "wx/timer.h" #include "wx/glcanvas.h" #include "wx/math.h" - -#if defined(__WXMAC__) || defined(__WXCOCOA__) -# ifdef __DARWIN__ -# include -# include -# else -# include -# include -# endif -#else -# include -# include -#endif - -// disabled because this has apparently changed in OpenGL 1.2, so doesn't link -// correctly if this is on... -#ifdef GL_EXT_vertex_array -#undef GL_EXT_vertex_array -#endif - -#include +#include "wx/log.h" +#include "wx/cmdline.h" +#include "wx/wfstream.h" +#include "wx/zstream.h" +#include "wx/txtstrm.h" #include "isosurf.h" #include "../../sample.xpm" -// The following part is taken largely unchanged from the original C Version - -GLboolean speed_test = GL_FALSE; -GLboolean use_vertex_arrays = GL_FALSE; - -GLboolean doubleBuffer = GL_TRUE; - -GLboolean smooth = GL_TRUE; -GLboolean lighting = GL_TRUE; - - -#define MAXVERTS 10000 - -static GLfloat verts[MAXVERTS][3]; -static GLfloat norms[MAXVERTS][3]; -static GLint numverts; - -static GLfloat xrot; -static GLfloat yrot; - - -static void read_surface(const char *filename) -{ - std::ifstream inFile(filename); - numverts = 0; - if ( !inFile ) - { - wxLogError("Couldn't read \"%s\"", filename); - return; - } +// global options which can be set through command-line options +GLboolean g_use_vertex_arrays = GL_FALSE; +GLboolean g_doubleBuffer = GL_TRUE; +GLboolean g_smooth = GL_TRUE; +GLboolean g_lighting = GL_TRUE; - while ((inFile >> verts[numverts][0] >> verts[numverts][1] >> verts[numverts][2] - >> norms[numverts][0] >> norms[numverts][1] >> norms[numverts][2]) && numvertsIsOk()) + { + wxLogError("Cannot load '%s' type of files!", filename.c_str()); + delete stream; + 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; + + while (!stream->Eof() && m_numverts < MAXVERTS)// && m_numverts> m_verts[m_numverts][0] >> m_verts[m_numverts][1] >> m_verts[m_numverts][2]; + inFile >> m_norms[m_numverts][0] >> m_norms[m_numverts][1] >> m_norms[m_numverts][2]; + + m_numverts++; + } + + // discard last vertex; it is a zero caused by the EOF + m_numverts--; + } + + delete stream; + + wxLogMessage(_T("Loaded %d vertices, %d triangles from '%s'"), + m_numverts, m_numverts-2, filename.c_str()); +} + void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) { // This is a dummy, to avoid an endless succession of paint messages. @@ -370,7 +246,32 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) // or more than one wxGLContext in the application. SetCurrent(*m_glRC); - draw1(); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glPushMatrix(); + glRotatef( m_yrot, 0.0f, 1.0f, 0.0f ); + glRotatef( m_xrot, 1.0f, 0.0f, 0.0f ); + + // draw the surface + if (g_use_vertex_arrays) + { + glDrawArrays( GL_TRIANGLE_STRIP, 0, m_numverts ); + } + else + { + glBegin( GL_TRIANGLE_STRIP ); + + for (int i=0;i