Moved wxGLCanvas to more normal positions
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6326 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
31
samples/opengl/cube/Makefile
Normal file
31
samples/opengl/cube/Makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# File: Makefile
|
||||
# Author: Robert Roebling
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Robert Roebling
|
||||
#
|
||||
# Makefile for OpenGl demo (GTK version)
|
||||
#
|
||||
# This makefile requires wxWindows/GTK to be
|
||||
# installed (possibly using "make install")
|
||||
# on your system.
|
||||
#
|
||||
|
||||
CC = gcc
|
||||
WXCONFIG=../../../wx-config
|
||||
WXINCLUDE=-I../../../include
|
||||
WXLIB=-L../../../lib
|
||||
|
||||
cube: cube.o # glcanvas.o
|
||||
$(CC) -o cube cube.o `$(WXCONFIG) --libs` $(WXLIB) -lMesaGL -lMesaGLU
|
||||
|
||||
cube.o: cube.cpp
|
||||
$(CC) `$(WXCONFIG) --cflags` -I../../gtk $(WXINCLUDE) -c cube.cpp
|
||||
|
||||
glcanvas.o: ../../gtk/glcanvas.cpp
|
||||
$(CC) `$(WXCONFIG) --cflags` `gtk-config --cflags` -I../../gtk $(WXINCLUDE) -c ../../gtk/glcanvas.cpp
|
||||
|
||||
clean:
|
||||
rm -f *.o cube
|
||||
|
508
samples/opengl/cube/cube.cpp
Normal file
508
samples/opengl/cube/cube.cpp
Normal file
@@ -0,0 +1,508 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: cube.cpp
|
||||
// Purpose: wxGLCanvas demo program
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
#include "wx/log.h"
|
||||
|
||||
#include "cube.h"
|
||||
|
||||
#ifndef __WXMSW__ // for wxStopWatch, see remark below
|
||||
#include <sys/time.h>
|
||||
#include <sys/unistd.h>
|
||||
#else
|
||||
#include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#define ID_NEW_WINDOW 10000
|
||||
#define ID_DEF_ROTATE_LEFT_KEY 10001
|
||||
#define ID_DEF_ROTATE_RIGHT_KEY 10002
|
||||
|
||||
/*----------------------------------------------------------
|
||||
Control to get a keycode
|
||||
----------------------------------------------------------*/
|
||||
class ScanCodeCtrl : public wxTextCtrl
|
||||
{
|
||||
public:
|
||||
ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code,
|
||||
const wxPoint& pos, const wxSize& size );
|
||||
void OnChar( wxKeyEvent& event ) { } /* do nothing */
|
||||
void OnKeyDown(wxKeyEvent& event);
|
||||
private:
|
||||
// any class wishing to process wxWindows events must use this macro
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl )
|
||||
EVT_CHAR( ScanCodeCtrl::OnChar )
|
||||
EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code,
|
||||
const wxPoint& pos, const wxSize& size )
|
||||
: wxTextCtrl( parent, id, "", pos, size )
|
||||
{ wxString buf;
|
||||
buf.Printf( "0x%04x", code );
|
||||
SetValue( buf );
|
||||
}
|
||||
|
||||
void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event )
|
||||
{ wxString buf;
|
||||
buf.Printf( "0x%04x", event.KeyCode() );
|
||||
SetValue( buf );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
Dialog for defining a keypress
|
||||
-------------------------------------------------------------------*/
|
||||
|
||||
class ScanCodeDialog : public wxDialog
|
||||
{
|
||||
public:
|
||||
ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code,
|
||||
const wxString &descr, const wxString& title );
|
||||
int GetValue();
|
||||
private:
|
||||
ScanCodeCtrl *m_ScanCode;
|
||||
wxTextCtrl *m_Description;
|
||||
};
|
||||
|
||||
ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id,
|
||||
const int code, const wxString &descr, const wxString& title )
|
||||
: wxDialog( parent, id, title, wxPoint(-1, -1), wxSize(96*2,76*2) )
|
||||
{
|
||||
new wxStaticText( this, -1, "Scancode", wxPoint(4*2,3*2),
|
||||
wxSize(31*2,12*2) );
|
||||
m_ScanCode = new ScanCodeCtrl( this, -1, code, wxPoint(37*2,6*2),
|
||||
wxSize(53*2,14*2) );
|
||||
|
||||
new wxStaticText( this, -1, "Description", wxPoint(4*2,24*2),
|
||||
wxSize(32*2,12*2) );
|
||||
m_Description = new wxTextCtrl( this, -1, descr, wxPoint(37*2,27*2),
|
||||
wxSize(53*2,14*2) );
|
||||
|
||||
new wxButton( this, wxID_OK, "Ok", wxPoint(20*2,50*2), wxSize(20*2,13*2) );
|
||||
new wxButton( this, wxID_CANCEL, "Cancel", wxPoint(44*2,50*2),
|
||||
wxSize(25*2,13*2) );
|
||||
}
|
||||
|
||||
int ScanCodeDialog::GetValue()
|
||||
{
|
||||
int code;
|
||||
wxString buf = m_ScanCode->GetValue();
|
||||
sscanf( buf.c_str(), "%i", &code );
|
||||
return( code );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Utility function to get the elapsed time (in msec) since a given point
|
||||
in time (in sec) (because current version of wxGetElapsedTime doesn<73>t
|
||||
works right with glibc-2.1 and linux, at least for me)
|
||||
-----------------------------------------------------------------------*/
|
||||
unsigned long wxStopWatch( unsigned long *sec_base )
|
||||
{
|
||||
unsigned long secs,msec;
|
||||
|
||||
#ifndef __WXMSW__ // think every unice has gettimeofday
|
||||
struct timeval tv;
|
||||
gettimeofday( &tv, (struct timezone *)NULL );
|
||||
secs = tv.tv_sec;
|
||||
msec = tv.tv_usec/1000;
|
||||
#else
|
||||
struct timeb tb;
|
||||
|
||||
ftime( &tb );
|
||||
|
||||
secs = tb.time;
|
||||
|
||||
msec = tb.millitm;
|
||||
|
||||
#endif
|
||||
|
||||
if( *sec_base == 0 )
|
||||
*sec_base = secs;
|
||||
|
||||
return( (secs-*sec_base)*1000 + msec );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
Implementation of Test-GLCanvas
|
||||
-----------------------------------------------------------------*/
|
||||
|
||||
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||
EVT_SIZE(TestGLCanvas::OnSize)
|
||||
EVT_PAINT(TestGLCanvas::OnPaint)
|
||||
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground)
|
||||
EVT_KEY_DOWN( TestGLCanvas::OnKeyDown )
|
||||
EVT_KEY_UP( TestGLCanvas::OnKeyUp )
|
||||
EVT_ENTER_WINDOW( TestGLCanvas::OnEnterWindow )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
unsigned long TestGLCanvas::m_secbase = 0;
|
||||
int TestGLCanvas::m_TimeInitialized = 0;
|
||||
unsigned long TestGLCanvas::m_xsynct;
|
||||
unsigned long TestGLCanvas::m_gsynct;
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
|
||||
wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name )
|
||||
{
|
||||
m_init = FALSE;
|
||||
m_gllist = 0;
|
||||
m_rleft = WXK_LEFT;
|
||||
m_rright = WXK_RIGHT;
|
||||
}
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, const TestGLCanvas &other,
|
||||
wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
|
||||
const wxString& name ) :
|
||||
wxGLCanvas(parent, other.GetContext(), id, pos, size, style, name )
|
||||
{
|
||||
m_init = FALSE;
|
||||
m_gllist = other.m_gllist; /* share display list */
|
||||
m_rleft = WXK_LEFT;
|
||||
m_rright = WXK_RIGHT;
|
||||
}
|
||||
|
||||
TestGLCanvas::~TestGLCanvas()
|
||||
{
|
||||
}
|
||||
|
||||
void TestGLCanvas::Render()
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
|
||||
#ifndef __WXMOTIF__
|
||||
if (!GetContext()) return;
|
||||
#endif
|
||||
|
||||
SetCurrent();
|
||||
/* init OpenGL once, but after SetCurrent */
|
||||
if (!m_init)
|
||||
{
|
||||
InitGL();
|
||||
m_init = TRUE;
|
||||
}
|
||||
|
||||
/* clear color and depth buffers */
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if( m_gllist == 0 )
|
||||
{
|
||||
m_gllist = glGenLists( 1 );
|
||||
glNewList( m_gllist, GL_COMPILE_AND_EXECUTE );
|
||||
/* draw six faces of a cube */
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f( 0.0F, 0.0F, 1.0F);
|
||||
glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F, 0.5F);
|
||||
glVertex3f(-0.5F,-0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F);
|
||||
|
||||
glNormal3f( 0.0F, 0.0F,-1.0F);
|
||||
glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F, 0.5F,-0.5F);
|
||||
glVertex3f( 0.5F, 0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F);
|
||||
|
||||
glNormal3f( 0.0F, 1.0F, 0.0F);
|
||||
glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F, 0.5F,-0.5F);
|
||||
glVertex3f(-0.5F, 0.5F,-0.5F); glVertex3f(-0.5F, 0.5F, 0.5F);
|
||||
|
||||
glNormal3f( 0.0F,-1.0F, 0.0F);
|
||||
glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F);
|
||||
glVertex3f( 0.5F,-0.5F, 0.5F); glVertex3f(-0.5F,-0.5F, 0.5F);
|
||||
|
||||
glNormal3f( 1.0F, 0.0F, 0.0F);
|
||||
glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F);
|
||||
glVertex3f( 0.5F,-0.5F,-0.5F); glVertex3f( 0.5F, 0.5F,-0.5F);
|
||||
|
||||
glNormal3f(-1.0F, 0.0F, 0.0F);
|
||||
glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F,-0.5F, 0.5F);
|
||||
glVertex3f(-0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F,-0.5F);
|
||||
glEnd();
|
||||
|
||||
glEndList();
|
||||
}
|
||||
else
|
||||
glCallList( m_gllist );
|
||||
|
||||
glFlush();
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnEnterWindow( wxMouseEvent& event )
|
||||
{
|
||||
SetFocus();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnPaint( wxPaintEvent& event )
|
||||
{
|
||||
Render();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
int width, height;
|
||||
GetClientSize(& width, & height);
|
||||
|
||||
#ifndef __WXMOTIF__
|
||||
if (GetContext())
|
||||
#endif
|
||||
{
|
||||
SetCurrent();
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
|
||||
{
|
||||
// Do nothing, to avoid flashing.
|
||||
}
|
||||
|
||||
void TestGLCanvas::InitGL()
|
||||
{
|
||||
SetCurrent();
|
||||
|
||||
/* set viewing projection */
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
|
||||
|
||||
/* position viewer */
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glTranslatef(0.0F, 0.0F, -2.0F);
|
||||
|
||||
/* position object */
|
||||
glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
|
||||
glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
}
|
||||
|
||||
GLfloat TestGLCanvas::CalcRotateSpeed( unsigned long acceltime )
|
||||
{
|
||||
GLfloat t,v;
|
||||
|
||||
t = ((GLfloat)acceltime) / 1000.0f;
|
||||
|
||||
if( t < 0.5f )
|
||||
v = t;
|
||||
else if( t < 1.0f )
|
||||
v = t * (2.0f - t);
|
||||
else
|
||||
v = 0.75f;
|
||||
|
||||
return(v);
|
||||
}
|
||||
|
||||
GLfloat TestGLCanvas::CalcRotateAngle( unsigned long lasttime,
|
||||
unsigned long acceltime )
|
||||
{
|
||||
GLfloat t,s1,s2;
|
||||
|
||||
t = ((GLfloat)(acceltime - lasttime)) / 1000.0f;
|
||||
s1 = CalcRotateSpeed( lasttime );
|
||||
s2 = CalcRotateSpeed( acceltime );
|
||||
|
||||
return( t * (s1 + s2) * 135.0f );
|
||||
}
|
||||
|
||||
void TestGLCanvas::Action( long code, unsigned long lasttime,
|
||||
unsigned long acceltime )
|
||||
{
|
||||
GLfloat angle = CalcRotateAngle( lasttime, acceltime );
|
||||
|
||||
if (code == m_rleft)
|
||||
Rotate( angle );
|
||||
else if (code == m_rright)
|
||||
Rotate( -angle );
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnKeyDown( wxKeyEvent& event )
|
||||
{
|
||||
long evkey = event.KeyCode();
|
||||
if (evkey == 0) return;
|
||||
|
||||
if (!m_TimeInitialized)
|
||||
{
|
||||
m_TimeInitialized = 1;
|
||||
m_xsynct = event.m_timeStamp;
|
||||
m_gsynct = wxStopWatch(&m_secbase);
|
||||
|
||||
m_Key = evkey;
|
||||
m_StartTime = 0;
|
||||
m_LastTime = 0;
|
||||
m_LastRedraw = 0;
|
||||
}
|
||||
|
||||
unsigned long currTime = event.m_timeStamp - m_xsynct;
|
||||
|
||||
if (evkey != m_Key)
|
||||
{
|
||||
m_Key = evkey;
|
||||
m_LastRedraw = m_StartTime = m_LastTime = currTime;
|
||||
}
|
||||
|
||||
if (currTime >= m_LastRedraw) // Redraw:
|
||||
{
|
||||
Action( m_Key, m_LastTime-m_StartTime, currTime-m_StartTime );
|
||||
|
||||
m_LastRedraw = wxStopWatch(&m_secbase) - m_gsynct;
|
||||
m_LastTime = currTime;
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnKeyUp( wxKeyEvent& event )
|
||||
{
|
||||
m_Key = 0;
|
||||
m_StartTime = 0;
|
||||
m_LastTime = 0;
|
||||
m_LastRedraw = 0;
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void TestGLCanvas::Rotate( GLfloat deg )
|
||||
{
|
||||
SetCurrent();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glRotatef((GLfloat)deg, 0.0F, 0.0F, 1.0F);
|
||||
Refresh(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
Main Window
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
||||
EVT_MENU( ID_NEW_WINDOW, MyFrame::OnNewWindow)
|
||||
EVT_MENU( ID_DEF_ROTATE_LEFT_KEY, MyFrame::OnDefRotateLeftKey)
|
||||
EVT_MENU( ID_DEF_ROTATE_RIGHT_KEY, MyFrame::OnDefRotateRightKey)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// My frame constructor
|
||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style)
|
||||
: wxFrame(frame, -1, title, pos, size, style)
|
||||
{
|
||||
m_canvas = NULL;
|
||||
}
|
||||
|
||||
// Intercept menu commands
|
||||
void MyFrame::OnExit(wxCommandEvent& event)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void MyFrame::OnNewWindow()
|
||||
{
|
||||
MyFrame *frame = new MyFrame(NULL, "Cube OpenGL Demo Clone",
|
||||
wxPoint(50, 50), wxSize(400, 300));
|
||||
// Give it an icon
|
||||
#ifdef wx_msw
|
||||
frame->SetIcon(wxIcon("mondrian"));
|
||||
#endif
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *winMenu = new wxMenu;
|
||||
|
||||
winMenu->Append(wxID_EXIT, "&Close");
|
||||
winMenu->Append(ID_NEW_WINDOW, "&New" );
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(winMenu, "&Window");
|
||||
|
||||
winMenu = new wxMenu;
|
||||
winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, "Rotate &left");
|
||||
winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, "Rotate &right");
|
||||
menuBar->Append(winMenu, "&Key");
|
||||
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
frame->m_canvas = new TestGLCanvas( frame, *m_canvas, -1,
|
||||
wxPoint(0, 0), wxSize(200, 200) );
|
||||
|
||||
// Show the frame
|
||||
frame->Show(TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::OnDefRotateLeftKey()
|
||||
{
|
||||
ScanCodeDialog dial( this, -1, m_canvas->m_rleft,
|
||||
wxString("Left"), "Define key" );
|
||||
int result = dial.ShowModal();
|
||||
if( result == wxID_OK )
|
||||
m_canvas->m_rleft = dial.GetValue();
|
||||
}
|
||||
void MyFrame::OnDefRotateRightKey()
|
||||
{
|
||||
ScanCodeDialog dial( this, -1, m_canvas->m_rright,
|
||||
wxString("Right"), "Define key" );
|
||||
int result = dial.ShowModal();
|
||||
if( result == wxID_OK )
|
||||
m_canvas->m_rright = dial.GetValue();
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
Application object ( equivalent to main() )
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
wxLog::SetTraceMask(wxTraceMessages);
|
||||
|
||||
// Create the main frame window
|
||||
MyFrame *frame = new MyFrame(NULL, "Cube OpenGL Demo", wxPoint(50, 50),
|
||||
wxSize(400, 300));
|
||||
// Give it an icon
|
||||
#ifdef wx_msw
|
||||
frame->SetIcon(wxIcon("mondrian"));
|
||||
#endif
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *winMenu = new wxMenu;
|
||||
|
||||
winMenu->Append(wxID_EXIT, "&Close");
|
||||
winMenu->Append(ID_NEW_WINDOW, "&New" );
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(winMenu, "&Window");
|
||||
|
||||
winMenu = new wxMenu;
|
||||
winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, "Rotate &left");
|
||||
winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, "Rotate &right");
|
||||
menuBar->Append(winMenu, "&Key");
|
||||
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200));
|
||||
|
||||
// Show the frame
|
||||
frame->Show(TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
93
samples/opengl/cube/cube.h
Normal file
93
samples/opengl/cube/cube.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: cube.h
|
||||
// Purpose: wxGLCanvas demo program
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_CUBE_H_
|
||||
#define _WX_CUBE_H_
|
||||
|
||||
#include <wx/glcanvas.h>
|
||||
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit(void);
|
||||
};
|
||||
|
||||
// Define a new frame type
|
||||
class TestGLCanvas;
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
void OnExit(wxCommandEvent& event);
|
||||
void OnNewWindow();
|
||||
void OnDefRotateLeftKey();
|
||||
void OnDefRotateRightKey();
|
||||
|
||||
public:
|
||||
TestGLCanvas* m_canvas;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class TestGLCanvas: public wxGLCanvas
|
||||
{
|
||||
friend class MyFrame;
|
||||
public:
|
||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1,
|
||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
||||
long style = 0, const wxString& name = "TestGLCanvas");
|
||||
TestGLCanvas(wxWindow *parent, const TestGLCanvas &other,
|
||||
const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0,
|
||||
const wxString& name = "TestGLCanvas" );
|
||||
|
||||
~TestGLCanvas(void);
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnEraseBackground(wxEraseEvent& event);
|
||||
void OnKeyDown(wxKeyEvent& event);
|
||||
void OnKeyUp(wxKeyEvent& event);
|
||||
void OnEnterWindow( wxMouseEvent& event );
|
||||
|
||||
void Render( void );
|
||||
void InitGL(void);
|
||||
void Rotate( GLfloat deg );
|
||||
static GLfloat CalcRotateSpeed( unsigned long acceltime );
|
||||
static GLfloat CalcRotateAngle( unsigned long lasttime,
|
||||
unsigned long acceltime );
|
||||
void Action( long code, unsigned long lasttime,
|
||||
unsigned long acceltime );
|
||||
|
||||
private:
|
||||
bool m_init;
|
||||
GLuint m_gllist;
|
||||
long m_rleft;
|
||||
long m_rright;
|
||||
|
||||
static unsigned long m_secbase;
|
||||
static int m_TimeInitialized;
|
||||
static unsigned long m_xsynct;
|
||||
static unsigned long m_gsynct;
|
||||
|
||||
long m_Key;
|
||||
unsigned long m_StartTime;
|
||||
unsigned long m_LastTime;
|
||||
unsigned long m_LastRedraw;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#endif
|
||||
|
3
samples/opengl/cube/cube.rc
Normal file
3
samples/opengl/cube/cube.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
#include "wx/msw/wx.rc"
|
||||
|
18
samples/opengl/cube/makefile.b32
Normal file
18
samples/opengl/cube/makefile.b32
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright:
|
||||
#
|
||||
# Makefile : Builds sample for 32-bit BC++
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=cube
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
OBJECTS = $(TARGET).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.b32
|
||||
|
21
samples/opengl/cube/makefile.bcc
Normal file
21
samples/opengl/cube/makefile.bcc
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# File: makefile.bcc
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
#
|
||||
# Builds a BC++ 16-bit sample
|
||||
|
||||
!if "$(WXWIN)" == ""
|
||||
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
|
||||
!endif
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=cube
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
OBJECTS = $(TARGET).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.bcc
|
||||
|
18
samples/opengl/cube/makefile.g95
Normal file
18
samples/opengl/cube/makefile.g95
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart, 1999
|
||||
#
|
||||
# Makefile for wxWindows sample (Cygwin/Mingw32).
|
||||
|
||||
WXDIR = ../../..
|
||||
|
||||
TARGET=cube
|
||||
#EXTRACPPFLAGS=-I../../win
|
||||
EXTRALIBS=-lopengl32 -lglu32
|
||||
OBJECTS = $(TARGET).o
|
||||
|
||||
include $(WXDIR)/src/makeprog.g95
|
||||
|
23
samples/opengl/cube/makefile.unx
Normal file
23
samples/opengl/cube/makefile.unx
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Julian Smart
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for cube example (UNIX).
|
||||
|
||||
PROGRAM=cube
|
||||
|
||||
OPENGLHOME=/home/jacs/mesa/Mesa-2.3
|
||||
|
||||
EXTRACPPFLAGS=-I$(OPENGLHOME)/include
|
||||
EXTRALDFLAGS=-L$(OPENGLHOME)/lib
|
||||
EXTRALDLIBS=-lMesaGL -lMesaGLU
|
||||
|
||||
OBJECTS=$(PROGRAM).o
|
||||
|
||||
include ../../../src/makeprog.env
|
||||
|
26
samples/opengl/cube/makefile.vc
Normal file
26
samples/opengl/cube/makefile.vc
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
!if "$(FINAL)" == "1"
|
||||
!else
|
||||
LIBEXT=_d
|
||||
!endif
|
||||
|
||||
PROGRAM=cube
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
#EXTRAINC=-I..\..\win
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas$(LIBEXT).lib glu32.lib opengl32.lib
|
||||
EXTRALIBS=glu32.lib opengl32.lib
|
||||
|
||||
!include $(WXDIR)\src\makeprog.vc
|
||||
|
17
samples/opengl/cube/makefile.wat
Normal file
17
samples/opengl/cube/makefile.wat
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile for WATCOM
|
||||
#
|
||||
# Created by Julian Smart, January 1999
|
||||
#
|
||||
#
|
||||
|
||||
WXDIR = $(%WXWIN)
|
||||
|
||||
PROGRAM = cube
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
|
||||
!include $(WXDIR)\src\makeprog.wat
|
||||
|
||||
|
BIN
samples/opengl/cube/mondrian.ico
Normal file
BIN
samples/opengl/cube/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
32
samples/opengl/isosurf/Makefile
Normal file
32
samples/opengl/isosurf/Makefile
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# File: Makefile
|
||||
# Author: Robert Roebling
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Robert Roebling
|
||||
#
|
||||
# Makefile for OpenGl demo (GTK version)
|
||||
#
|
||||
# This makefile requires wxWindows/GTK to be
|
||||
# installed (possibly using "make install")
|
||||
# on your system.
|
||||
#
|
||||
|
||||
CC = g++
|
||||
WXCONFIG=../../../wx-config
|
||||
WXINCLUDE=-I../../../include
|
||||
WXLIB=-L../../../lib
|
||||
|
||||
isosurf: isosurf.o # glcanvas.o
|
||||
$(CC) -o isosurf \
|
||||
isosurf.o \
|
||||
`$(WXCONFIG) --libs` $(WXLIB) -lMesaGL -lMesaGLU
|
||||
|
||||
isosurf.o: isosurf.cpp
|
||||
$(CC) `$(WXCONFIG) --cflags` -I../../gtk $(WXINCLUDE) -c isosurf.cpp
|
||||
|
||||
glcanvas.o: ../../gtk/glcanvas.cpp
|
||||
$(CC) `$(WXCONFIG) --cflags` `gtk-config --cflags` -I../../gtk -c $(WXINCLUDE) ../../gtk/glcanvas.cpp
|
||||
|
||||
clean:
|
||||
rm -f *.o isosurf
|
412
samples/opengl/isosurf/isosurf.cpp
Normal file
412
samples/opengl/isosurf/isosurf.cpp
Normal file
@@ -0,0 +1,412 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
#include "wx/timer.h"
|
||||
#include "wx/glcanvas.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "isosurf.h"
|
||||
|
||||
// The following part is taken largely unchanged from the original C Version
|
||||
|
||||
#include <math.h>
|
||||
|
||||
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( char *filename )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
f = fopen(filename,"r");
|
||||
if (!f) {
|
||||
wxString msg("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] );
|
||||
numverts++;
|
||||
}
|
||||
numverts--;
|
||||
|
||||
printf("%d vertices, %d triangles\n", numverts, numverts-2);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
static void draw_surface( void )
|
||||
{
|
||||
GLint i;
|
||||
|
||||
#ifdef GL_EXT_vertex_array
|
||||
if (use_vertex_arrays) {
|
||||
glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
glBegin( GL_TRIANGLE_STRIP );
|
||||
for (i=0;i<numverts;i++) {
|
||||
glNormal3fv( norms[i] );
|
||||
glVertex3fv( verts[i] );
|
||||
}
|
||||
glEnd();
|
||||
#ifdef GL_EXT_vertex_array
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void draw1(void)
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
glPushMatrix();
|
||||
glRotatef( yrot, 0.0, 1.0, 0.0 );
|
||||
glRotatef( xrot, 1.0, 0.0, 0.0 );
|
||||
|
||||
draw_surface();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
||||
|
||||
static void InitMaterials(void)
|
||||
{
|
||||
static float ambient[] = {0.1, 0.1, 0.1, 1.0};
|
||||
static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
|
||||
static float position0[] = {0.0, 0.0, 20.0, 0.0};
|
||||
static float position1[] = {0.0, 0.0, -20.0, 0.0};
|
||||
static float front_mat_shininess[] = {60.0};
|
||||
static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
|
||||
static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
|
||||
/*
|
||||
static float back_mat_shininess[] = {60.0};
|
||||
static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
|
||||
static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
|
||||
*/
|
||||
static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
|
||||
static float lmodel_twoside[] = {GL_FALSE};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position0);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, position1);
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
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)
|
||||
{
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
InitMaterials();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0.0, 0.0, -6.0 );
|
||||
|
||||
#ifdef GL_EXT_vertex_array
|
||||
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 );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void Reshape(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
}
|
||||
|
||||
|
||||
static GLenum Args(int argc, char **argv)
|
||||
{
|
||||
GLint i;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-sb") == 0) {
|
||||
doubleBuffer = GL_FALSE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-db") == 0) {
|
||||
doubleBuffer = GL_TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-speed") == 0) {
|
||||
speed_test = GL_TRUE;
|
||||
doubleBuffer = GL_TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-va") == 0) {
|
||||
use_vertex_arrays = GL_TRUE;
|
||||
}
|
||||
else {
|
||||
wxString msg("Bad option: ");
|
||||
msg += argv[i];
|
||||
wxMessageBox(msg);
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
// The following part was written for wxWindows 1.66
|
||||
MyFrame *frame = NULL;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
// `Main program' equivalent, creating windows and returning main app frame
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
Args(argc, argv);
|
||||
|
||||
// Create the main frame window
|
||||
frame = new MyFrame(NULL, "Isosurf GL Sample", wxPoint(50, 50), wxSize(200, 200));
|
||||
|
||||
// Give it an icon
|
||||
frame->SetIcon(wxIcon("mondrian"));
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
|
||||
fileMenu->Append(wxID_EXIT, "E&xit");
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(fileMenu, "&File");
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
// Make a TestGLCanvas
|
||||
|
||||
// JACS
|
||||
#ifdef __WXMSW__
|
||||
int *gl_attrib = NULL;
|
||||
#else
|
||||
int gl_attrib[20] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 1,
|
||||
GLX_DOUBLEBUFFER, None };
|
||||
#endif
|
||||
|
||||
if(!doubleBuffer)
|
||||
{
|
||||
printf("don't have double buffer, disabling\n");
|
||||
#ifdef __WXGTK__
|
||||
gl_attrib[9] = None;
|
||||
#endif
|
||||
doubleBuffer = GL_FALSE;
|
||||
}
|
||||
frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200), 0, "TestGLCanvas",
|
||||
gl_attrib);
|
||||
|
||||
// Show the frame
|
||||
frame->Show(TRUE);
|
||||
|
||||
frame->m_canvas->SetCurrent();
|
||||
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, -1, title, pos, size, style)
|
||||
{
|
||||
m_canvas = NULL;
|
||||
}
|
||||
|
||||
// Intercept menu commands
|
||||
void MyFrame::OnExit(wxCommandEvent& event)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
/*
|
||||
* TestGLCanvas implementation
|
||||
*/
|
||||
|
||||
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||
EVT_SIZE(TestGLCanvas::OnSize)
|
||||
EVT_PAINT(TestGLCanvas::OnPaint)
|
||||
EVT_CHAR(TestGLCanvas::OnChar)
|
||||
EVT_MOUSE_EVENTS(TestGLCanvas::OnMouseEvent)
|
||||
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name, int* gl_attrib):
|
||||
wxGLCanvas(parent, id, pos, size, style, name, gl_attrib)
|
||||
{
|
||||
parent->Show(TRUE);
|
||||
SetCurrent();
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TestGLCanvas::~TestGLCanvas(void)
|
||||
{
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnPaint( wxPaintEvent& event )
|
||||
{
|
||||
// This is a dummy, to avoid an endless succession of paint messages.
|
||||
// OnPaint handlers must always create a wxPaintDC.
|
||||
wxPaintDC dc(this);
|
||||
|
||||
draw1();
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
SetCurrent();
|
||||
int width, height;
|
||||
GetClientSize(& width, & height);
|
||||
Reshape(width, height);
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnChar(wxKeyEvent& event)
|
||||
{
|
||||
switch(event.KeyCode()) {
|
||||
case WXK_ESCAPE:
|
||||
exit(0);
|
||||
case WXK_LEFT:
|
||||
yrot -= 15.0;
|
||||
break;
|
||||
case WXK_RIGHT:
|
||||
yrot += 15.0;
|
||||
break;
|
||||
case WXK_UP:
|
||||
xrot += 15.0;
|
||||
break;
|
||||
case WXK_DOWN:
|
||||
xrot -= 15.0;
|
||||
break;
|
||||
case 's': case 'S':
|
||||
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;
|
||||
default:
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Refresh(FALSE);
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
static int dragging = 0;
|
||||
static float last_x, last_y;
|
||||
|
||||
//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();
|
||||
} else
|
||||
dragging = 0;
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
|
||||
{
|
||||
// Do nothing, to avoid flashing.
|
||||
}
|
||||
|
BIN
samples/opengl/isosurf/isosurf.dat.gz
Normal file
BIN
samples/opengl/isosurf/isosurf.dat.gz
Normal file
Binary file not shown.
52
samples/opengl/isosurf/isosurf.h
Normal file
52
samples/opengl/isosurf/isosurf.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: isosurf.h
|
||||
// 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
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_ISOSURF_H_
|
||||
#define _WX_ISOSURF_H_
|
||||
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
{ public:
|
||||
bool OnInit(void);
|
||||
};
|
||||
|
||||
class TestGLCanvas: public wxGLCanvas
|
||||
{
|
||||
public:
|
||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "TestGLCanvas",
|
||||
int* gl_attrib = NULL);
|
||||
~TestGLCanvas(void);
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnEraseBackground(wxEraseEvent& event);
|
||||
void OnChar(wxKeyEvent& event);
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
long style = wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
void OnExit(wxCommandEvent& event);
|
||||
public:
|
||||
TestGLCanvas* m_canvas;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#endif
|
||||
|
3
samples/opengl/isosurf/isosurf.rc
Normal file
3
samples/opengl/isosurf/isosurf.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
#include "wx/msw/wx.rc"
|
||||
|
22
samples/opengl/isosurf/makefile.b32
Normal file
22
samples/opengl/isosurf/makefile.b32
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright:
|
||||
#
|
||||
# Makefile : Builds sample for 32-bit BC++
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=isosurf
|
||||
# EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
# EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
OBJECTS = $(TARGET).obj
|
||||
EXTRATARGETS=isosurf.dat
|
||||
|
||||
!include $(WXDIR)\src\makeprog.b32
|
||||
|
||||
isosurf.dat: isosurf.dat.gz
|
||||
gzip -c -d isosurf.dat.gz > isosurf.dat
|
||||
|
25
samples/opengl/isosurf/makefile.bcc
Normal file
25
samples/opengl/isosurf/makefile.bcc
Normal file
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# File: makefile.bcc
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
#
|
||||
# Builds a BC++ 16-bit sample
|
||||
|
||||
!if "$(WXWIN)" == ""
|
||||
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
|
||||
!endif
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=isosurf
|
||||
# EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
# EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
OBJECTS = $(TARGET).obj
|
||||
EXTRATARGETS=isosurf.dat
|
||||
|
||||
!include $(WXDIR)\src\makeprog.bcc
|
||||
|
||||
isosurf.dat: isosurf.dat.gz
|
||||
gzip -c -d isosurf.dat.gz > isosurf.dat
|
||||
|
20
samples/opengl/isosurf/makefile.g95
Normal file
20
samples/opengl/isosurf/makefile.g95
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart, 1999
|
||||
#
|
||||
# Makefile for wxWindows sample (Cygwin/Mingw32).
|
||||
|
||||
WXDIR = ../../..
|
||||
|
||||
TARGET=isosurf
|
||||
# EXTRACPPFLAGS=-I../../win
|
||||
EXTRALIBS=-lopengl32 -lglu32
|
||||
OBJECTS = $(TARGET).o
|
||||
|
||||
include $(WXDIR)/src/makeprog.g95
|
||||
|
||||
isosurf.dat: isosurf.dat.gz
|
||||
gzip -c -d isosurf.dat.gz > isosurf.dat
|
27
samples/opengl/isosurf/makefile.unx
Normal file
27
samples/opengl/isosurf/makefile.unx
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Julian Smart
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for isosurf example (UNIX).
|
||||
|
||||
PROGRAM=isosurf
|
||||
|
||||
OPENGLHOME=/home/jacs/mesa/Mesa-2.3
|
||||
|
||||
EXTRACPPFLAGS=-I$(OPENGLHOME)/include
|
||||
EXTRALDFLAGS=-L$(OPENGLHOME)/lib
|
||||
EXTRALDLIBS=-lMesaGL -lMesaGLU
|
||||
|
||||
OBJECTS=$(PROGRAM).o
|
||||
EXTRATARGETS=isosurf.dat
|
||||
|
||||
include ../../../src/makeprog.env
|
||||
|
||||
isosurf.dat: isosurf.dat.gz
|
||||
gzip -c -d isosurf.dat.gz > isosurf.dat
|
||||
|
30
samples/opengl/isosurf/makefile.vc
Normal file
30
samples/opengl/isosurf/makefile.vc
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
!if "$(FINAL)" == "1"
|
||||
!else
|
||||
LIBEXT=_d
|
||||
!endif
|
||||
|
||||
PROGRAM=isosurf
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
#EXTRAINC=-I..\..\win
|
||||
EXTRALIBS=glu32.lib opengl32.lib
|
||||
EXTRATARGETS=isosurf.dat
|
||||
|
||||
!include $(WXDIR)\src\makeprog.vc
|
||||
|
||||
isosurf.dat: isosurf.dat.gz
|
||||
gzip -c -d isosurf.dat.gz > isosurf.dat
|
||||
|
||||
|
20
samples/opengl/isosurf/makefile.wat
Normal file
20
samples/opengl/isosurf/makefile.wat
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Makefile for WATCOM
|
||||
#
|
||||
# Created by Julian Smart, January 1999
|
||||
#
|
||||
#
|
||||
|
||||
WXDIR = $(%WXWIN)
|
||||
|
||||
PROGRAM = isosurf
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
EXTRATARGETS=isosurf.dat
|
||||
|
||||
!include $(WXDIR)\src\makeprog.wat
|
||||
|
||||
isosurf.dat: isosurf.dat.gz
|
||||
gzip -c -d isosurf.dat.gz > isosurf.dat
|
||||
|
BIN
samples/opengl/isosurf/mondrian.ico
Normal file
BIN
samples/opengl/isosurf/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
37
samples/opengl/penguin/Makefile
Normal file
37
samples/opengl/penguin/Makefile
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# File: Makefile
|
||||
# Author: Robert Roebling
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Robert Roebling
|
||||
#
|
||||
# Makefile for OpenGL demo (GTK version)
|
||||
#
|
||||
# This makefile requires wxWindows/GTK to be
|
||||
# installed (possibly using "make install")
|
||||
# on your system.
|
||||
#
|
||||
|
||||
CPP = gcc
|
||||
CC = gcc
|
||||
WXCONFIG=../../../wx-config
|
||||
WXINCLUDE=-I../../../include
|
||||
WXLIB=-L../../../lib
|
||||
|
||||
Penguin: penguin.o trackball.o lw.o # glcanvas.o
|
||||
$(CPP) -o Penguin penguin.o trackball.o lw.o `$(WXCONFIG) --libs` $(WXLIB) -lMesaGL -lMesaGLU
|
||||
|
||||
penguin.o: penguin.cpp
|
||||
$(CPP) `$(WXCONFIG) --cflags` -I../../gtk $(WXINCLUDE) -c penguin.cpp
|
||||
|
||||
lw.o: lw.cpp
|
||||
$(CPP) `$(WXCONFIG) --cflags` -I../../gtk $(WXINCLUDE) -c lw.cpp
|
||||
|
||||
trackball.o: trackball.c
|
||||
$(CC) `$(WXCONFIG) --cflags` -I../../gtk $(WXINCLUDE) -c trackball.c
|
||||
|
||||
glcanvas.o: ../../gtk/glcanvas.cpp
|
||||
$(CPP) `$(WXCONFIG) --cflags` `gtk-config --cflags` -g -I../../gtk $(WXINCLUDE) -c ../../gtk/glcanvas.cpp
|
||||
|
||||
clean:
|
||||
rm -f *.o Penguin
|
427
samples/opengl/penguin/lw.cpp
Normal file
427
samples/opengl/penguin/lw.cpp
Normal file
@@ -0,0 +1,427 @@
|
||||
/*
|
||||
* Copyright (C) 1998 Janne L<>f <jlof@mail.student.oulu.fi>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "lw.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#define wxInt32 int
|
||||
#define wxUint32 unsigned int
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#define MK_ID(a,b,c,d) ((((wxUint32)(a))<<24)| \
|
||||
(((wxUint32)(b))<<16)| \
|
||||
(((wxUint32)(c))<< 8)| \
|
||||
(((wxUint32)(d)) ))
|
||||
|
||||
#define ID_FORM MK_ID('F','O','R','M')
|
||||
#define ID_LWOB MK_ID('L','W','O','B')
|
||||
#define ID_PNTS MK_ID('P','N','T','S')
|
||||
#define ID_SRFS MK_ID('S','R','F','S')
|
||||
#define ID_SURF MK_ID('S','U','R','F')
|
||||
#define ID_POLS MK_ID('P','O','L','S')
|
||||
#define ID_COLR MK_ID('C','O','L','R')
|
||||
|
||||
static wxInt32 read_char(FILE *f)
|
||||
{
|
||||
int c = fgetc(f);
|
||||
return c;
|
||||
}
|
||||
|
||||
static wxInt32 read_short(FILE *f)
|
||||
{
|
||||
return (read_char(f)<<8) | read_char(f);
|
||||
}
|
||||
|
||||
static wxInt32 read_long(FILE *f)
|
||||
{
|
||||
return (read_char(f)<<24) | (read_char(f)<<16) | (read_char(f)<<8) | read_char(f);
|
||||
}
|
||||
|
||||
static GLfloat read_float(FILE *f)
|
||||
{
|
||||
wxInt32 x = read_long(f);
|
||||
return *(GLfloat*)&x;
|
||||
}
|
||||
|
||||
static int read_string(FILE *f, char *s)
|
||||
{
|
||||
int c;
|
||||
int cnt = 0;
|
||||
do {
|
||||
c = read_char(f);
|
||||
if (cnt < LW_MAX_NAME_LEN)
|
||||
s[cnt] = c;
|
||||
else
|
||||
s[LW_MAX_NAME_LEN-1] = 0;
|
||||
cnt++;
|
||||
} while (c != 0);
|
||||
/* if length of string (including \0) is odd skip another byte */
|
||||
if (cnt%2) {
|
||||
read_char(f);
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static void read_srfs(FILE *f, int nbytes, lwObject *lwo)
|
||||
{
|
||||
int guess_cnt = lwo->material_cnt;
|
||||
|
||||
while (nbytes > 0) {
|
||||
lwMaterial *material;
|
||||
|
||||
/* allocate more memory for materials if needed */
|
||||
if (guess_cnt <= lwo->material_cnt) {
|
||||
guess_cnt += guess_cnt/2 + 4;
|
||||
lwo->material = (lwMaterial*) realloc(lwo->material, sizeof(lwMaterial)*guess_cnt);
|
||||
}
|
||||
material = lwo->material + lwo->material_cnt++;
|
||||
|
||||
/* read name */
|
||||
nbytes -= read_string(f,material->name);
|
||||
|
||||
/* defaults */
|
||||
material->r = 0.7;
|
||||
material->g = 0.7;
|
||||
material->b = 0.7;
|
||||
}
|
||||
lwo->material = (lwMaterial*) realloc(lwo->material, sizeof(lwMaterial)*lwo->material_cnt);
|
||||
}
|
||||
|
||||
|
||||
static void read_surf(FILE *f, int nbytes, lwObject *lwo)
|
||||
{
|
||||
int i;
|
||||
char name[LW_MAX_NAME_LEN];
|
||||
lwMaterial *material = NULL;
|
||||
|
||||
/* read surface name */
|
||||
nbytes -= read_string(f,name);
|
||||
|
||||
/* find material */
|
||||
for (i=0; i< lwo->material_cnt; i++) {
|
||||
if (strcmp(lwo->material[i].name,name) == 0) {
|
||||
material = &lwo->material[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* read values */
|
||||
while (nbytes > 0) {
|
||||
int id = read_long(f);
|
||||
int len = read_short(f);
|
||||
nbytes -= 6 + len + (len%2);
|
||||
|
||||
switch (id) {
|
||||
case ID_COLR:
|
||||
material->r = read_char(f) / 255.0;
|
||||
material->g = read_char(f) / 255.0;
|
||||
material->b = read_char(f) / 255.0;
|
||||
read_char(f); /* dummy */
|
||||
break;
|
||||
default:
|
||||
fseek(f, len+(len%2), SEEK_CUR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void read_pols(FILE *f, int nbytes, lwObject *lwo)
|
||||
{
|
||||
int guess_cnt = lwo->face_cnt;
|
||||
|
||||
while (nbytes > 0) {
|
||||
lwFace *face;
|
||||
int i;
|
||||
|
||||
/* allocate more memory for polygons if necessary */
|
||||
if (guess_cnt <= lwo->face_cnt) {
|
||||
guess_cnt += guess_cnt + 4;
|
||||
lwo->face = (lwFace*) realloc((void*) lwo->face, sizeof(lwFace)*guess_cnt);
|
||||
}
|
||||
face = lwo->face + lwo->face_cnt++;
|
||||
|
||||
/* number of points in this face */
|
||||
face->index_cnt = read_short(f);
|
||||
nbytes -= 2;
|
||||
|
||||
/* allocate space for points */
|
||||
face->index = (int*) calloc(sizeof(int)*face->index_cnt,1);
|
||||
|
||||
/* read points in */
|
||||
for (i=0; i<face->index_cnt; i++) {
|
||||
face->index[i] = read_short(f);
|
||||
nbytes -= 2;
|
||||
}
|
||||
|
||||
/* read surface material */
|
||||
face->material = read_short(f);
|
||||
nbytes -= 2;
|
||||
|
||||
/* skip over detail polygons */
|
||||
if (face->material < 0) {
|
||||
int det_cnt;
|
||||
face->material = -face->material;
|
||||
det_cnt = read_short(f);
|
||||
nbytes -= 2;
|
||||
while (det_cnt-- > 0) {
|
||||
int cnt = read_short(f);
|
||||
fseek(f, cnt*2+2, SEEK_CUR);
|
||||
nbytes -= cnt*2+2;
|
||||
}
|
||||
}
|
||||
face->material -= 1;
|
||||
}
|
||||
/* readjust to true size */
|
||||
lwo->face = (lwFace*) realloc(lwo->face, sizeof(lwFace)*lwo->face_cnt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void read_pnts(FILE *f, int nbytes, lwObject *lwo)
|
||||
{
|
||||
int i;
|
||||
lwo->vertex_cnt = nbytes / 12;
|
||||
lwo->vertex = (float*) calloc(sizeof(GLfloat)*lwo->vertex_cnt*3, 1);
|
||||
for (i=0; i<lwo->vertex_cnt; i++) {
|
||||
lwo->vertex[i*3+0] = read_float(f);
|
||||
lwo->vertex[i*3+1] = read_float(f);
|
||||
lwo->vertex[i*3+2] = read_float(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int lw_is_lwobject(const char *lw_file)
|
||||
{
|
||||
FILE *f = fopen(lw_file, "rb");
|
||||
if (f) {
|
||||
wxInt32 form = read_long(f);
|
||||
wxInt32 nlen = read_long(f);
|
||||
wxInt32 lwob = read_long(f);
|
||||
fclose(f);
|
||||
if (form == ID_FORM && nlen != 0 && lwob == ID_LWOB)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
lwObject *lw_object_read(const char *lw_file)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
lwObject *lw_object = NULL;
|
||||
|
||||
wxInt32 form_bytes = 0;
|
||||
wxInt32 read_bytes = 0;
|
||||
|
||||
/* open file */
|
||||
f = fopen(lw_file, "rb");
|
||||
if (f == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* check for headers */
|
||||
if (read_long(f) != ID_FORM) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
form_bytes = read_long(f);
|
||||
read_bytes += 4;
|
||||
|
||||
if (read_long(f) != ID_LWOB) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create new lwObject */
|
||||
lw_object = (lwObject*) calloc(sizeof(lwObject),1);
|
||||
|
||||
/* read chunks */
|
||||
while (read_bytes < form_bytes) {
|
||||
wxInt32 id = read_long(f);
|
||||
wxInt32 nbytes = read_long(f);
|
||||
read_bytes += 8 + nbytes + (nbytes%2);
|
||||
|
||||
switch (id) {
|
||||
case ID_PNTS:
|
||||
read_pnts(f, nbytes, lw_object);
|
||||
break;
|
||||
case ID_POLS:
|
||||
read_pols(f, nbytes, lw_object);
|
||||
break;
|
||||
case ID_SRFS:
|
||||
read_srfs(f, nbytes, lw_object);
|
||||
break;
|
||||
case ID_SURF:
|
||||
read_surf(f, nbytes, lw_object);
|
||||
break;
|
||||
default:
|
||||
fseek(f, nbytes + (nbytes%2), SEEK_CUR);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return lw_object;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lw_object_free(lwObject *lw_object)
|
||||
{
|
||||
if (lw_object->face) {
|
||||
int i;
|
||||
for (i=0; i<lw_object->face_cnt; i++)
|
||||
free(lw_object->face[i].index);
|
||||
free(lw_object->face);
|
||||
}
|
||||
free(lw_object->material);
|
||||
free(lw_object->vertex);
|
||||
free(lw_object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define PX(i) (lw_object->vertex[face->index[i]*3+0])
|
||||
#define PY(i) (lw_object->vertex[face->index[i]*3+1])
|
||||
#define PZ(i) (lw_object->vertex[face->index[i]*3+2])
|
||||
void lw_object_show(const lwObject *lw_object)
|
||||
{
|
||||
int i,j;
|
||||
int prev_index_cnt = -1;
|
||||
int prev_material = -1;
|
||||
GLfloat prev_nx = 0;
|
||||
GLfloat prev_ny = 0;
|
||||
GLfloat prev_nz = 0;
|
||||
|
||||
for (i=0; i<lw_object->face_cnt; i++) {
|
||||
GLfloat ax,ay,az,bx,by,bz,nx,ny,nz,r;
|
||||
const lwFace *face = lw_object->face+i;
|
||||
|
||||
/* ignore faces with less than 3 points */
|
||||
if (face->index_cnt < 3)
|
||||
continue;
|
||||
|
||||
/* calculate normal */
|
||||
ax = PX(1) - PX(0);
|
||||
ay = PY(1) - PY(0);
|
||||
az = PZ(1) - PZ(0);
|
||||
|
||||
bx = PX(face->index_cnt-1) - PX(0);
|
||||
by = PY(face->index_cnt-1) - PY(0);
|
||||
bz = PZ(face->index_cnt-1) - PZ(0);
|
||||
|
||||
nx = ay * bz - az * by;
|
||||
ny = az * bx - ax * bz;
|
||||
nz = ax * by - ay * bx;
|
||||
|
||||
r = sqrt(nx*nx + ny*ny + nz*nz);
|
||||
if (r < 0.000001) /* avoid division by zero */
|
||||
continue;
|
||||
nx /= r;
|
||||
ny /= r;
|
||||
nz /= r;
|
||||
|
||||
/* glBegin/glEnd */
|
||||
if (prev_index_cnt != face->index_cnt || prev_index_cnt > 4) {
|
||||
if (prev_index_cnt > 0) glEnd();
|
||||
prev_index_cnt = face->index_cnt;
|
||||
switch (face->index_cnt) {
|
||||
case 3:
|
||||
glBegin(GL_TRIANGLES);
|
||||
break;
|
||||
case 4:
|
||||
glBegin(GL_QUADS);
|
||||
break;
|
||||
default:
|
||||
glBegin(GL_POLYGON);
|
||||
}
|
||||
}
|
||||
|
||||
/* update material if necessary */
|
||||
if (prev_material != face->material) {
|
||||
prev_material = face->material;
|
||||
glColor3f(lw_object->material[face->material].r,
|
||||
lw_object->material[face->material].g,
|
||||
lw_object->material[face->material].b);
|
||||
}
|
||||
|
||||
/* update normal if necessary */
|
||||
if (nx != prev_nx || ny != prev_ny || nz != prev_nz) {
|
||||
prev_nx = nx;
|
||||
prev_ny = ny;
|
||||
prev_nz = nz;
|
||||
glNormal3f(nx,ny,nz);
|
||||
}
|
||||
|
||||
/* draw polygon/triangle/quad */
|
||||
for (j=0; j<face->index_cnt; j++)
|
||||
glVertex3f(PX(j),PY(j),PZ(j));
|
||||
|
||||
}
|
||||
|
||||
/* if glBegin was called call glEnd */
|
||||
if (prev_index_cnt > 0)
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
GLfloat lw_object_radius(const lwObject *lwo)
|
||||
{
|
||||
int i;
|
||||
double max_radius = 0.0;
|
||||
|
||||
for (i=0; i<lwo->vertex_cnt; i++) {
|
||||
GLfloat *v = &lwo->vertex[i*3];
|
||||
double r = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
|
||||
if (r > max_radius)
|
||||
max_radius = r;
|
||||
}
|
||||
return sqrt(max_radius);
|
||||
}
|
||||
|
||||
void lw_object_scale(lwObject *lwo, GLfloat scale)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<lwo->vertex_cnt; i++) {
|
||||
lwo->vertex[i*3+0] *= scale;
|
||||
lwo->vertex[i*3+1] *= scale;
|
||||
lwo->vertex[i*3+2] *= scale;
|
||||
}
|
||||
}
|
||||
|
||||
|
69
samples/opengl/penguin/lw.h
Normal file
69
samples/opengl/penguin/lw.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 1998 Janne L<>f <jlof@mail.student.oulu.fi>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LW_H
|
||||
#define LW_H
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#define LW_MAX_POINTS 200
|
||||
#define LW_MAX_NAME_LEN 500
|
||||
|
||||
typedef struct {
|
||||
char name[LW_MAX_NAME_LEN];
|
||||
GLfloat r,g,b;
|
||||
} lwMaterial;
|
||||
|
||||
typedef struct {
|
||||
int material; /* material of this face */
|
||||
int index_cnt; /* number of vertices */
|
||||
int *index; /* index to vertex */
|
||||
float *texcoord; /* u,v texture coordinates */
|
||||
} lwFace;
|
||||
|
||||
typedef struct {
|
||||
int face_cnt;
|
||||
lwFace *face;
|
||||
|
||||
int material_cnt;
|
||||
lwMaterial *material;
|
||||
|
||||
int vertex_cnt;
|
||||
GLfloat *vertex;
|
||||
|
||||
} lwObject;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int lw_is_lwobject(const char *lw_file);
|
||||
lwObject *lw_object_read(const char *lw_file);
|
||||
void lw_object_free( lwObject *lw_object);
|
||||
void lw_object_show(const lwObject *lw_object);
|
||||
|
||||
GLfloat lw_object_radius(const lwObject *lw_object);
|
||||
void lw_object_scale (lwObject *lw_object, GLfloat scale);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LW_H */
|
||||
|
18
samples/opengl/penguin/makefile.b32
Normal file
18
samples/opengl/penguin/makefile.b32
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright:
|
||||
#
|
||||
# Makefile : Builds sample for 32-bit BC++
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=penguin
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
OBJECTS = $(TARGET).obj lw.obj trackball.obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.b32
|
||||
|
21
samples/opengl/penguin/makefile.bcc
Normal file
21
samples/opengl/penguin/makefile.bcc
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# File: makefile.bcc
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
#
|
||||
# Builds a BC++ 16-bit sample
|
||||
|
||||
!if "$(WXWIN)" == ""
|
||||
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
|
||||
!endif
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=penguin
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
OBJECTS = $(TARGET).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.bcc
|
||||
|
18
samples/opengl/penguin/makefile.g95
Normal file
18
samples/opengl/penguin/makefile.g95
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart, 1999
|
||||
#
|
||||
# Makefile for wxWindows sample (Cygwin/Mingw32).
|
||||
|
||||
WXDIR = ../../..
|
||||
|
||||
TARGET=penguin
|
||||
#EXTRACPPFLAGS=-I../../win
|
||||
EXTRALIBS=-lopengl32 -lglu32
|
||||
OBJECTS = $(TARGET).o lw.o trackball.o
|
||||
|
||||
include $(WXDIR)/src/makeprog.g95
|
||||
|
21
samples/opengl/penguin/makefile.unx
Normal file
21
samples/opengl/penguin/makefile.unx
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Julian Smart
|
||||
#
|
||||
# Makefile for penguin example (UNIX).
|
||||
|
||||
PROGRAM=penguin
|
||||
|
||||
OPENGLHOME=/home/jacs/mesa/Mesa-2.3
|
||||
|
||||
EXTRACPPFLAGS=-I$(OPENGLHOME)/include # -I../../motif
|
||||
EXTRALDFLAGS=-L$(OPENGLHOME)/lib
|
||||
EXTRALDLIBS=-lMesaGL -lMesaGLU
|
||||
|
||||
OBJECTS=$(PROGRAM).o trackball.o lw.o
|
||||
|
||||
include ../../../src/makeprog.env
|
||||
|
30
samples/opengl/penguin/makefile.vc
Normal file
30
samples/opengl/penguin/makefile.vc
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
!if "$(FINAL)" == "1"
|
||||
!else
|
||||
LIBEXT=_d
|
||||
!endif
|
||||
|
||||
PROGRAM=penguin
|
||||
OBJECTS = $(PROGRAM).obj trackball.obj lw.obj
|
||||
#EXTRAINC=-I..\..\win
|
||||
EXTRALIBS=glu32.lib opengl32.lib
|
||||
|
||||
!include $(WXDIR)\src\makeprog.vc
|
||||
|
||||
lw.obj: lw.cpp lw.h
|
||||
$(cc) @<<
|
||||
$(CPPFLAGS2) /c $*.$(SRCSUFF)
|
||||
<<
|
||||
|
17
samples/opengl/penguin/makefile.wat
Normal file
17
samples/opengl/penguin/makefile.wat
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile for WATCOM
|
||||
#
|
||||
# Created by Julian Smart, January 1999
|
||||
#
|
||||
#
|
||||
|
||||
WXDIR = $(%WXWIN)
|
||||
|
||||
PROGRAM = penguin
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
#EXTRALIBS=$(WXDIR)\lib\glcanvas.lib
|
||||
#EXTRACPPFLAGS=-I$(WXDIR)\utils\glcanvas\win
|
||||
|
||||
!include $(WXDIR)\src\makeprog.wat
|
||||
|
||||
|
236
samples/opengl/penguin/penguin.cpp
Normal file
236
samples/opengl/penguin/penguin.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: penguin.cpp
|
||||
// Purpose: wxGLCanvas demo program
|
||||
// Author: Robert Roebling
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Robert Roebling
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
#include "penguin.h"
|
||||
#include <GL/glu.h>
|
||||
|
||||
#define VIEW_ASPECT 1.3
|
||||
|
||||
/* `Main program' equivalent, creating windows and returning main app frame */
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
|
||||
/* Create the main frame window */
|
||||
MyFrame *frame = new MyFrame(NULL, "wxWindows OpenGL Demo", wxPoint(50, 50), wxSize(400, 300));
|
||||
|
||||
/* Make a menubar */
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
|
||||
fileMenu->Append(wxID_EXIT, "E&xit");
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(fileMenu, "&File");
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200));
|
||||
|
||||
/* Load file wiht mesh data */
|
||||
frame->m_canvas->LoadLWO( "penguin.lwo" );
|
||||
|
||||
/* Show the frame */
|
||||
frame->Show(TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
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, -1, title, pos, size, style)
|
||||
{
|
||||
m_canvas = NULL;
|
||||
}
|
||||
|
||||
/* Intercept menu commands */
|
||||
void MyFrame::OnExit(wxCommandEvent& event)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||
EVT_SIZE(TestGLCanvas::OnSize)
|
||||
EVT_PAINT(TestGLCanvas::OnPaint)
|
||||
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground)
|
||||
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, name)
|
||||
{
|
||||
block = FALSE;
|
||||
}
|
||||
|
||||
TestGLCanvas::~TestGLCanvas(void)
|
||||
{
|
||||
/* destroy mesh */
|
||||
lw_object_free(info.lwobject);
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnPaint( wxPaintEvent& event )
|
||||
{
|
||||
/* must always be here */
|
||||
wxPaintDC dc(this);
|
||||
|
||||
#ifndef __WXMOTIF__
|
||||
if (!GetContext()) return;
|
||||
#endif
|
||||
|
||||
SetCurrent();
|
||||
|
||||
/* initialize OpenGL */
|
||||
if (info.do_init == TRUE)
|
||||
{
|
||||
InitGL();
|
||||
info.do_init = FALSE;
|
||||
}
|
||||
|
||||
/* view */
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
gluPerspective( info.zoom, VIEW_ASPECT, 1, 100 );
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
|
||||
/* clear */
|
||||
glClearColor( .3, .4, .6, 1 );
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
/* transformations */
|
||||
GLfloat m[4][4];
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0, 0, -30 );
|
||||
build_rotmatrix( m,info.quat );
|
||||
glMultMatrixf( &m[0][0] );
|
||||
|
||||
/* draw object */
|
||||
lw_object_show( info.lwobject );
|
||||
|
||||
/* flush */
|
||||
glFlush();
|
||||
|
||||
/* swap */
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
int width, height;
|
||||
GetClientSize(& width, & height);
|
||||
|
||||
#ifndef __WXMOTIF__
|
||||
if (GetContext())
|
||||
#endif
|
||||
{
|
||||
SetCurrent();
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)
|
||||
{
|
||||
/* Do nothing, to avoid flashing on MSW */
|
||||
}
|
||||
|
||||
void TestGLCanvas::LoadLWO(const wxString &filename)
|
||||
{
|
||||
/* test if lightwave object */
|
||||
if (!lw_is_lwobject(filename)) return;
|
||||
|
||||
/* read lightwave object */
|
||||
lwObject *lwobject = lw_object_read(filename);
|
||||
|
||||
/* scale */
|
||||
lw_object_scale(lwobject, 10.0 / lw_object_radius(lwobject));
|
||||
|
||||
/* set up mesh info */
|
||||
info.do_init = TRUE;
|
||||
info.lwobject = lwobject;
|
||||
info.beginx = 0;
|
||||
info.beginy = 0;
|
||||
info.zoom = 45;
|
||||
trackball( info.quat, 0.0, 0.0, 0.0, 0.0 );
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnMouse( wxMouseEvent& event )
|
||||
{
|
||||
wxSize sz(GetClientSize());
|
||||
if (event.Dragging())
|
||||
{
|
||||
/* drag in progress, simulate trackball */
|
||||
float spin_quat[4];
|
||||
trackball(spin_quat,
|
||||
(2.0*info.beginx - sz.x) / sz.x,
|
||||
( sz.y - 2.0*info.beginy) / sz.y,
|
||||
( 2.0*event.GetX() - sz.x) / sz.x,
|
||||
( sz.y - 2.0*event.GetY()) / sz.y);
|
||||
|
||||
add_quats( spin_quat, info.quat, info.quat );
|
||||
|
||||
/* orientation has changed, redraw mesh */
|
||||
Refresh(FALSE);
|
||||
}
|
||||
|
||||
info.beginx = event.GetX();
|
||||
info.beginy = event.GetY();
|
||||
}
|
||||
|
||||
void TestGLCanvas::InitGL(void)
|
||||
{
|
||||
GLfloat light0_pos[4] = { -50.0, 50.0, 0.0, 0.0 };
|
||||
GLfloat light0_color[4] = { .6, .6, .6, 1.0 }; /* white light */
|
||||
GLfloat light1_pos[4] = { 50.0, 50.0, 0.0, 0.0 };
|
||||
GLfloat light1_color[4] = { .4, .4, 1, 1.0 }; /* cold blue light */
|
||||
|
||||
/* remove back faces */
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* speedups */
|
||||
glEnable(GL_DITHER);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
||||
glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
|
||||
|
||||
/* light */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
}
|
||||
|
||||
|
84
samples/opengl/penguin/penguin.h
Normal file
84
samples/opengl/penguin/penguin.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: penguin.h
|
||||
// Purpose: wxGLCanvas demo program
|
||||
// Author: Robert Roebling
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Robert Roebling
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PENGUIN_H_
|
||||
#define _WX_PENGUIN_H_
|
||||
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/menu.h"
|
||||
#include "wx/dcclient.h"
|
||||
|
||||
#include "wx/glcanvas.h"
|
||||
|
||||
extern "C" {
|
||||
#include "lw.h"
|
||||
#include "trackball.h"
|
||||
}
|
||||
|
||||
/* information needed to display lightwave mesh */
|
||||
typedef struct
|
||||
{
|
||||
// gint do_init; /* true if initgl not yet called */
|
||||
int do_init;
|
||||
lwObject *lwobject; /* lightwave object mesh */
|
||||
float beginx,beginy; /* position of mouse */
|
||||
float quat[4]; /* orientation of object */
|
||||
float zoom; /* field of view in degrees */
|
||||
} mesh_info;
|
||||
|
||||
|
||||
/* Define a new application type */
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit(void);
|
||||
};
|
||||
|
||||
/* Define a new frame type */
|
||||
class TestGLCanvas;
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
long style = wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
void OnExit(wxCommandEvent& event);
|
||||
public:
|
||||
TestGLCanvas* m_canvas;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
||||
class TestGLCanvas: public wxGLCanvas
|
||||
{
|
||||
public:
|
||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "TestGLCanvas");
|
||||
~TestGLCanvas(void);
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnEraseBackground(wxEraseEvent& event);
|
||||
void LoadLWO( const wxString &filename);
|
||||
void OnMouse( wxMouseEvent& event );
|
||||
void InitGL(void);
|
||||
|
||||
mesh_info info;
|
||||
bool block;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
samples/opengl/penguin/penguin.lwo
Normal file
BIN
samples/opengl/penguin/penguin.lwo
Normal file
Binary file not shown.
3
samples/opengl/penguin/penguin.rc
Normal file
3
samples/opengl/penguin/penguin.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
/* mondrian ICON "mondrian.ico" */
|
||||
#include "wx/msw/wx.rc"
|
||||
|
78
samples/opengl/penguin/trackball.h
Normal file
78
samples/opengl/penguin/trackball.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
|
||||
* ALL RIGHTS RESERVED
|
||||
* Permission to use, copy, modify, and distribute this software for
|
||||
* any purpose and without fee is hereby granted, provided that the above
|
||||
* copyright notice appear in all copies and that both the copyright notice
|
||||
* and this permission notice appear in supporting documentation, and that
|
||||
* the name of Silicon Graphics, Inc. not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission.
|
||||
*
|
||||
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
||||
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
||||
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
||||
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
||||
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
||||
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
||||
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* US Government Users Restricted Rights
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
||||
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
||||
* clause at DFARS 252.227-7013 and/or in similar or successor
|
||||
* clauses in the FAR or the DOD or NASA FAR Supplement.
|
||||
* Unpublished-- rights reserved under the copyright laws of the
|
||||
* United States. Contractor/manufacturer is Silicon Graphics,
|
||||
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
||||
*
|
||||
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
||||
*/
|
||||
/*
|
||||
* trackball.h
|
||||
* A virtual trackball implementation
|
||||
* Written by Gavin Bell for Silicon Graphics, November 1988.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pass the x and y coordinates of the last and current positions of
|
||||
* the mouse, scaled so they are from (-1.0 ... 1.0).
|
||||
*
|
||||
* The resulting rotation is returned as a quaternion rotation in the
|
||||
* first paramater.
|
||||
*/
|
||||
void
|
||||
trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
|
||||
|
||||
/*
|
||||
* Given two quaternions, add them together to get a third quaternion.
|
||||
* Adding quaternions to get a compound rotation is analagous to adding
|
||||
* translations to get a compound translation. When incrementally
|
||||
* adding rotations, the first argument here should be the new
|
||||
* rotation, the second and third the total rotation (which will be
|
||||
* over-written with the resulting new total rotation).
|
||||
*/
|
||||
void
|
||||
add_quats(float *q1, float *q2, float *dest);
|
||||
|
||||
/*
|
||||
* A useful function, builds a rotation matrix in Matrix based on
|
||||
* given quaternion.
|
||||
*/
|
||||
void
|
||||
build_rotmatrix(float m[4][4], float q[4]);
|
||||
|
||||
/*
|
||||
* This function computes a quaternion based on an axis (defined by
|
||||
* the given vector) and an angle about which to rotate. The angle is
|
||||
* expressed in radians. The result is put into the third argument.
|
||||
*/
|
||||
void
|
||||
axis_to_quat(float a[3], float phi, float q[4]);
|
||||
|
Reference in New Issue
Block a user