// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#include "wx/wx.h"
#endif
-#if !wxUSE_GLCANVAS
-#error Please set wxUSE_GLCANVAS to 1 in setup.h.
-#endif
-
#include "wx/timer.h"
#include "wx/glcanvas.h"
# include <GL/glu.h>
#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 "isosurf.h"
// The following part is taken largely unchanged from the original C Version
static GLfloat yrot;
-static void read_surface( char *filename )
+static void read_surface( wxChar *filename )
{
FILE *f;
- f = fopen(filename,"r");
+ f = wxFopen(filename,_T("r"));
if (!f) {
- wxString msg("Couldn't read ");
+ wxString msg(_T("Couldn't read "));
msg += filename;
wxMessageBox(msg);
return;
numverts = 0;
while (!feof(f) && numverts<MAXVERTS) {
fscanf( f, "%f %f %f %f %f %f",
- &verts[numverts][0], &verts[numverts][1], &verts[numverts][2],
- &norms[numverts][0], &norms[numverts][1], &norms[numverts][2] );
+ &verts[numverts][0], &verts[numverts][1], &verts[numverts][2],
+ &norms[numverts][0], &norms[numverts][1], &norms[numverts][2] );
numverts++;
}
numverts--;
- printf("%d vertices, %d triangles\n", numverts, numverts-2);
+ wxPrintf(_T("%d vertices, %d triangles\n"), numverts, numverts-2);
fclose(f);
}
#endif
}
-
-static void Reshape(int width, int height)
-{
- glViewport(0, 0, (GLint)width, (GLint)height);
-}
-
-
-static GLenum Args(int argc, char **argv)
+static GLenum Args(int argc, wxChar **argv)
{
GLint i;
for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-sb") == 0) {
+ if (wxStrcmp(argv[i], _T("-sb")) == 0) {
doubleBuffer = GL_FALSE;
}
- else if (strcmp(argv[i], "-db") == 0) {
+ else if (wxStrcmp(argv[i], _T("-db")) == 0) {
doubleBuffer = GL_TRUE;
}
- else if (strcmp(argv[i], "-speed") == 0) {
+ else if (wxStrcmp(argv[i], _T("-speed")) == 0) {
speed_test = GL_TRUE;
doubleBuffer = GL_TRUE;
}
- else if (strcmp(argv[i], "-va") == 0) {
+ else if (wxStrcmp(argv[i], _T("-va")) == 0) {
use_vertex_arrays = GL_TRUE;
}
else {
- wxString msg("Bad option: ");
+ wxString msg(_T("Bad option: "));
msg += argv[i];
wxMessageBox(msg);
return GL_FALSE;
Args(argc, argv);
// Create the main frame window
- frame = new MyFrame(NULL, "Isosurf GL Sample", wxPoint(50, 50), wxSize(200, 200));
+ frame = new MyFrame(NULL, _T("Isosurf GL Sample"), wxPoint(50, 50), wxSize(200, 200));
// Give it an icon
- frame->SetIcon(wxIcon("mondrian"));
+ frame->SetIcon(wxIcon(_T("mondrian")));
// Make a menubar
wxMenu *fileMenu = new wxMenu;
- fileMenu->Append(wxID_EXIT, "E&xit");
+ fileMenu->Append(wxID_EXIT, _T("E&xit"));
wxMenuBar *menuBar = new wxMenuBar;
- menuBar->Append(fileMenu, "&File");
+ menuBar->Append(fileMenu, _T("&File"));
frame->SetMenuBar(menuBar);
// Make a TestGLCanvas
int *gl_attrib = NULL;
#else
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,
+ WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
+ WX_GL_DOUBLEBUFFER,
# ifdef __WXMAC__
- GL_NONE };
+ GL_NONE };
# else
- None };
+ None };
# endif
#endif
doubleBuffer = GL_FALSE;
}
- frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200),
- 0, "TestGLCanvas", gl_attrib );
+#if wxUSE_GLCANVAS
+
+ frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize,
+ 0, _T("TestGLCanvas"), gl_attrib );
// Show the frame
frame->Show(TRUE);
frame->m_canvas->SetCurrent();
- read_surface( "isosurf.dat" );
+ read_surface( _T("isosurf.dat") );
Init();
return TRUE;
+
+#else
+
+ wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), _T("Building error"), wxOK);
+
+ return FALSE;
+#endif
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
const wxSize& size, long style):
wxFrame(frame, -1, title, pos, size, style)
{
+#if wxUSE_GLCANVAS
m_canvas = NULL;
+#endif
}
// Intercept menu commands
-void MyFrame::OnExit(wxCommandEvent& event)
+void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
{
Destroy();
}
* TestGLCanvas implementation
*/
+#if wxUSE_GLCANVAS
+
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
EVT_SIZE(TestGLCanvas::OnSize)
EVT_PAINT(TestGLCanvas::OnPaint)
{
}
-void TestGLCanvas::OnPaint( wxPaintEvent& event )
+void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
// This is a dummy, to avoid an endless succession of paint messages.
// OnPaint handlers must always create a wxPaintDC.
void TestGLCanvas::OnSize(wxSizeEvent& event)
{
+ // this is also necessary to update the context on some platforms
+ wxGLCanvas::OnSize(event);
+
+ // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
+ int w, h;
+ GetClientSize(&w, &h);
#ifndef __WXMOTIF__
- if (!GetContext()) return;
+ if (GetContext())
#endif
-
- SetCurrent();
- int width, height;
- GetClientSize(& width, & height);
- Reshape(width, height);
+ {
+ SetCurrent();
+ glViewport(0, 0, (GLint) w, (GLint) h);
+ }
}
void TestGLCanvas::OnChar(wxKeyEvent& event)
{
- switch(event.KeyCode()) {
+ switch(event.GetKeyCode()) {
case WXK_ESCAPE:
- exit(0);
+ exit(0);
case WXK_LEFT:
- yrot -= 15.0;
- break;
+ yrot -= 15.0;
+ break;
case WXK_RIGHT:
- yrot += 15.0;
- break;
+ yrot += 15.0;
+ break;
case WXK_UP:
- xrot += 15.0;
- break;
+ xrot += 15.0;
+ break;
case WXK_DOWN:
- xrot -= 15.0;
- break;
+ xrot -= 15.0;
+ break;
case 's': case 'S':
- smooth = !smooth;
- if (smooth) {
- glShadeModel(GL_SMOOTH);
- } else {
- glShadeModel(GL_FLAT);
- }
- break;
+ smooth = !smooth;
+ if (smooth) {
+ glShadeModel(GL_SMOOTH);
+ } else {
+ glShadeModel(GL_FLAT);
+ }
+ break;
case 'l': case 'L':
- lighting = !lighting;
- if (lighting) {
- glEnable(GL_LIGHTING);
- } else {
- glDisable(GL_LIGHTING);
- }
- break;
+ lighting = !lighting;
+ if (lighting) {
+ glEnable(GL_LIGHTING);
+ } else {
+ glDisable(GL_LIGHTING);
+ }
+ break;
default:
{
event.Skip();
- return;
+ return;
}
}
//printf("%f %f %d\n", event.GetX(), event.GetY(), (int)event.LeftIsDown());
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();
+ 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();
} else
- dragging = 0;
+ dragging = 0;
}
-void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
+void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
// Do nothing, to avoid flashing.
}
+#endif
\ No newline at end of file