2000-02-28 03:22:57 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: isosurf.cpp
|
|
|
|
// Purpose: wxGLCanvas demo program
|
|
|
|
// Author: Brian Paul (original gltk version), Wolfram Gloger
|
|
|
|
// Modified by: Julian Smart
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
2002-03-17 09:16:03 -05:00
|
|
|
// Licence: wxWindows licence
|
2000-02-28 03:22:57 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2004-10-13 17:19:38 -04:00
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
#include "wx/timer.h"
|
|
|
|
#include "wx/glcanvas.h"
|
2004-12-14 15:52:13 -05:00
|
|
|
#include "wx/math.h"
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2004-10-01 10:26:19 -04:00
|
|
|
#if defined(__WXMAC__) || defined(__WXCOCOA__)
|
2003-11-14 23:21:10 -05:00
|
|
|
# ifdef __DARWIN__
|
|
|
|
# include <OpenGL/gl.h>
|
|
|
|
# include <OpenGL/glu.h>
|
|
|
|
# else
|
|
|
|
# include <gl.h>
|
|
|
|
# include <glu.h>
|
|
|
|
# endif
|
2001-07-22 10:57:47 -04:00
|
|
|
#else
|
2003-11-14 23:21:10 -05:00
|
|
|
# include <GL/gl.h>
|
|
|
|
# include <GL/glu.h>
|
2001-07-22 10:57:47 -04:00
|
|
|
#endif
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2001-11-16 02:17:37 -05:00
|
|
|
// 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
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
#include <fstream>
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
#include "isosurf.h"
|
2005-02-26 15:03:27 -05:00
|
|
|
#include "../../sample.xpm"
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
static void read_surface(const char *filename)
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2008-02-10 08:26:01 -05:00
|
|
|
std::ifstream inFile(filename);
|
|
|
|
numverts = 0;
|
|
|
|
|
|
|
|
if ( !inFile )
|
2003-11-14 23:21:10 -05:00
|
|
|
{
|
2008-02-10 08:26:01 -05:00
|
|
|
wxLogError("Couldn't read \"%s\"", filename);
|
2003-11-14 23:21:10 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
while ((inFile >> verts[numverts][0] >> verts[numverts][1] >> verts[numverts][2]
|
|
|
|
>> norms[numverts][0] >> norms[numverts][1] >> norms[numverts][2]) && numverts<MAXVERTS)
|
2003-11-14 23:21:10 -05:00
|
|
|
{
|
|
|
|
numverts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPrintf(_T("%d vertices, %d triangles\n"), numverts, numverts-2);
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
static void draw_surface()
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
GLint i;
|
2000-02-28 03:22:57 -05:00
|
|
|
|
|
|
|
#ifdef GL_EXT_vertex_array
|
2003-11-14 23:21:10 -05:00
|
|
|
if (use_vertex_arrays)
|
|
|
|
{
|
|
|
|
glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
|
|
|
|
}
|
|
|
|
else
|
2000-02-28 03:22:57 -05:00
|
|
|
#endif
|
2003-11-14 23:21:10 -05:00
|
|
|
{
|
|
|
|
glBegin( GL_TRIANGLE_STRIP );
|
|
|
|
for (i=0;i<numverts;i++)
|
|
|
|
{
|
|
|
|
glNormal3fv( norms[i] );
|
|
|
|
glVertex3fv( verts[i] );
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
static void draw1()
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
|
|
glPushMatrix();
|
2003-11-14 23:21:10 -05:00
|
|
|
glRotatef( yrot, 0.0f, 1.0f, 0.0f );
|
|
|
|
glRotatef( xrot, 1.0f, 0.0f, 0.0f );
|
2000-02-28 03:22:57 -05:00
|
|
|
|
|
|
|
draw_surface();
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
glFlush(); // Not really necessary: buffer swapping below implies glFlush()
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
static void InitMaterials()
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
static const GLfloat ambient[4] = {0.1f, 0.1f, 0.1f, 1.0f};
|
|
|
|
static const GLfloat diffuse[4] = {0.5f, 1.0f, 1.0f, 1.0f};
|
|
|
|
static const GLfloat position0[4] = {0.0f, 0.0f, 20.0f, 0.0f};
|
|
|
|
static const GLfloat position1[4] = {0.0f, 0.0f, -20.0f, 0.0f};
|
|
|
|
static const GLfloat front_mat_shininess[1] = {60.0f};
|
|
|
|
static const GLfloat front_mat_specular[4] = {0.2f, 0.2f, 0.2f, 1.0f};
|
|
|
|
static const GLfloat front_mat_diffuse[4] = {0.5f, 0.28f, 0.38f, 1.0f};
|
2000-02-28 03:22:57 -05:00
|
|
|
/*
|
2003-11-14 23:21:10 -05:00
|
|
|
static const GLfloat back_mat_shininess[1] = {60.0f};
|
|
|
|
static const GLfloat back_mat_specular[4] = {0.5f, 0.5f, 0.2f, 1.0f};
|
|
|
|
static const GLfloat back_mat_diffuse[4] = {1.0f, 1.0f, 0.2f, 1.0f};
|
2000-02-28 03:22:57 -05:00
|
|
|
*/
|
2003-11-14 23:21:10 -05:00
|
|
|
static const GLfloat lmodel_ambient[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
|
|
static const GLfloat lmodel_twoside[1] = {GL_FALSE};
|
2000-02-28 03:22:57 -05:00
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, position0);
|
|
|
|
glEnable(GL_LIGHT0);
|
2003-11-14 23:21:10 -05:00
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
|
|
|
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
|
|
|
|
glLightfv(GL_LIGHT1, GL_POSITION, position1);
|
|
|
|
glEnable(GL_LIGHT1);
|
2003-11-14 23:21:10 -05:00
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
|
|
|
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Init(void)
|
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
InitMaterials();
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef( 0.0, 0.0, -6.0 );
|
2000-02-28 03:22:57 -05:00
|
|
|
|
|
|
|
#ifdef GL_EXT_vertex_array
|
2003-11-14 23:21:10 -05:00
|
|
|
if (use_vertex_arrays)
|
|
|
|
{
|
|
|
|
glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts );
|
|
|
|
glNormalPointerEXT( GL_FLOAT, 0, numverts, norms );
|
|
|
|
glEnable( GL_VERTEX_ARRAY_EXT );
|
|
|
|
glEnable( GL_NORMAL_ARRAY_EXT );
|
|
|
|
}
|
2000-02-28 03:22:57 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-09-11 03:20:55 -04:00
|
|
|
static GLenum Args(int argc, wxChar **argv)
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
GLint i;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (wxStrcmp(argv[i], _T("-sb")) == 0)
|
|
|
|
{
|
|
|
|
doubleBuffer = GL_FALSE;
|
|
|
|
}
|
|
|
|
else if (wxStrcmp(argv[i], _T("-db")) == 0)
|
|
|
|
{
|
|
|
|
doubleBuffer = GL_TRUE;
|
|
|
|
}
|
|
|
|
else if (wxStrcmp(argv[i], _T("-speed")) == 0)
|
|
|
|
{
|
|
|
|
speed_test = GL_TRUE;
|
|
|
|
doubleBuffer = GL_TRUE;
|
|
|
|
}
|
|
|
|
else if (wxStrcmp(argv[i], _T("-va")) == 0)
|
|
|
|
{
|
|
|
|
use_vertex_arrays = GL_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString msg = _T("Bad option: ");
|
|
|
|
msg += argv[i];
|
|
|
|
wxMessageBox(msg);
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// `Main program' equivalent, creating windows and returning main app frame
|
2003-11-14 23:21:10 -05:00
|
|
|
bool MyApp::OnInit()
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
Args(argc, argv);
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
// Create the main frame window
|
2008-02-10 08:26:01 -05:00
|
|
|
new MyFrame(NULL, wxT("wxWidgets OpenGL Isosurf Sample"),
|
2003-11-14 23:21:10 -05:00
|
|
|
wxDefaultPosition, wxDefaultSize);
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
read_surface("isosurf.dat");
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// My frame constructor
|
|
|
|
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
|
|
|
const wxSize& size, long style)
|
|
|
|
: wxFrame(frame, wxID_ANY, title, pos, size, style),
|
|
|
|
m_canvas(NULL)
|
|
|
|
{
|
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *fileMenu = new wxMenu;
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
fileMenu->Append(wxID_EXIT, _T("E&xit"));
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append(fileMenu, _T("&File"));
|
2008-02-10 08:26:01 -05:00
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
|
|
|
|
// Make a TestGLCanvas
|
|
|
|
|
|
|
|
// JACS
|
|
|
|
#ifdef __WXMSW__
|
2003-11-14 23:21:10 -05:00
|
|
|
int *gl_attrib = NULL;
|
2000-02-28 03:22:57 -05:00
|
|
|
#else
|
2003-11-14 23:21:10 -05:00
|
|
|
int gl_attrib[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
|
|
|
|
WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
|
|
|
|
WX_GL_DOUBLEBUFFER,
|
2006-11-06 07:59:38 -05:00
|
|
|
# if defined(__WXMAC__) || defined(__WXCOCOA__)
|
2003-11-14 23:21:10 -05:00
|
|
|
GL_NONE };
|
2001-07-22 10:57:47 -04:00
|
|
|
# else
|
2003-11-14 23:21:10 -05:00
|
|
|
None };
|
2001-07-22 10:57:47 -04:00
|
|
|
# endif
|
2000-02-28 03:22:57 -05:00
|
|
|
#endif
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
if(!doubleBuffer)
|
|
|
|
{
|
|
|
|
printf("don't have double buffer, disabling\n");
|
2000-02-28 03:22:57 -05:00
|
|
|
#ifdef __WXGTK__
|
2003-11-14 23:21:10 -05:00
|
|
|
gl_attrib[9] = None;
|
2000-02-28 03:22:57 -05:00
|
|
|
#endif
|
2003-11-14 23:21:10 -05:00
|
|
|
doubleBuffer = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
// Show the frame
|
|
|
|
Show(true);
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
m_canvas = new TestGLCanvas(this, wxID_ANY, wxDefaultPosition,
|
|
|
|
GetClientSize(), 0, _T("TestGLCanvas"), gl_attrib );
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
2004-10-13 17:19:38 -04:00
|
|
|
delete m_canvas;
|
2003-11-14 23:21:10 -05:00
|
|
|
}
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
// Intercept menu commands
|
2003-11-14 23:21:10 -05:00
|
|
|
void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TestGLCanvas implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
|
|
|
EVT_SIZE(TestGLCanvas::OnSize)
|
|
|
|
EVT_PAINT(TestGLCanvas::OnPaint)
|
|
|
|
EVT_CHAR(TestGLCanvas::OnChar)
|
|
|
|
EVT_MOUSE_EVENTS(TestGLCanvas::OnMouseEvent)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
TestGLCanvas::TestGLCanvas(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxString& name,
|
|
|
|
int* gl_attrib)
|
|
|
|
: wxGLCanvas(parent, id, gl_attrib, pos, size,
|
|
|
|
style | wxFULL_REPAINT_ON_RESIZE, name)
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
2008-02-10 08:26:01 -05:00
|
|
|
// 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);
|
2003-11-14 23:21:10 -05:00
|
|
|
|
|
|
|
/* Make sure server supports the vertex array extension */
|
|
|
|
char* extensions = (char *) glGetString( GL_EXTENSIONS );
|
|
|
|
if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" ))
|
|
|
|
{
|
|
|
|
use_vertex_arrays = GL_FALSE;
|
|
|
|
}
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
TestGLCanvas::~TestGLCanvas()
|
|
|
|
{
|
|
|
|
delete m_glRC;
|
|
|
|
}
|
2000-02-28 03:22:57 -05:00
|
|
|
|
2003-09-11 03:20:55 -04:00
|
|
|
void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
2000-02-28 03:22:57 -05:00
|
|
|
{
|
|
|
|
// This is a dummy, to avoid an endless succession of paint messages.
|
|
|
|
// OnPaint handlers must always create a wxPaintDC.
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
// This is normally only necessary if there is more than one wxGLCanvas
|
|
|
|
// or more than one wxGLContext in the application.
|
|
|
|
SetCurrent(*m_glRC);
|
2000-07-21 06:16:53 -04:00
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
draw1();
|
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
|
|
|
{
|
2008-02-10 08:26:01 -05:00
|
|
|
// This is normally only necessary if there is more than one wxGLCanvas
|
|
|
|
// or more than one wxGLContext in the application.
|
|
|
|
SetCurrent(*m_glRC);
|
|
|
|
|
|
|
|
// It's up to the application code to update the OpenGL viewport settings.
|
|
|
|
// This is OK here 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.
|
|
|
|
glViewport(0, 0, event.GetSize().x, event.GetSize().y);
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGLCanvas::OnChar(wxKeyEvent& event)
|
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
switch( event.GetKeyCode() )
|
|
|
|
{
|
2000-02-28 03:22:57 -05:00
|
|
|
case WXK_ESCAPE:
|
2003-11-14 23:21:10 -05:00
|
|
|
wxTheApp->ExitMainLoop();
|
|
|
|
return;
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
case WXK_LEFT:
|
2003-11-14 23:21:10 -05:00
|
|
|
yrot -= 15.0;
|
|
|
|
break;
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
case WXK_RIGHT:
|
2003-11-14 23:21:10 -05:00
|
|
|
yrot += 15.0;
|
|
|
|
break;
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
case WXK_UP:
|
2003-11-14 23:21:10 -05:00
|
|
|
xrot += 15.0;
|
|
|
|
break;
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
case WXK_DOWN:
|
2003-11-14 23:21:10 -05:00
|
|
|
xrot -= 15.0;
|
|
|
|
break;
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
case 's': case 'S':
|
2003-11-14 23:21:10 -05:00
|
|
|
smooth = !smooth;
|
|
|
|
if (smooth)
|
|
|
|
{
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glShadeModel(GL_FLAT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-02-28 03:22:57 -05:00
|
|
|
case 'l': case 'L':
|
2003-11-14 23:21:10 -05:00
|
|
|
lighting = !lighting;
|
|
|
|
if (lighting)
|
|
|
|
{
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-02-28 03:22:57 -05:00
|
|
|
event.Skip();
|
2003-11-14 23:21:10 -05:00
|
|
|
return;
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
Refresh(false);
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
static int dragging = 0;
|
|
|
|
static float last_x, last_y;
|
|
|
|
|
2008-02-10 08:26:01 -05:00
|
|
|
// Allow default processing to happen, or else the canvas cannot gain focus
|
|
|
|
// (for key events).
|
|
|
|
event.Skip();
|
|
|
|
|
2003-11-14 23:21:10 -05:00
|
|
|
if(event.LeftIsDown())
|
|
|
|
{
|
|
|
|
if(!dragging)
|
|
|
|
{
|
|
|
|
dragging = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
yrot += (event.GetX() - last_x)*1.0;
|
|
|
|
xrot += (event.GetY() - last_y)*1.0;
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
last_x = event.GetX();
|
|
|
|
last_y = event.GetY();
|
2002-03-17 09:16:03 -05:00
|
|
|
}
|
2003-11-14 23:21:10 -05:00
|
|
|
else
|
2008-02-10 08:26:01 -05:00
|
|
|
{
|
2003-11-14 23:21:10 -05:00
|
|
|
dragging = 0;
|
2008-02-10 08:26:01 -05:00
|
|
|
}
|
2000-02-28 03:22:57 -05:00
|
|
|
}
|
|
|
|
|