Wx-GLCanvas-0.09/0000755000076500000240000000000011240340556012777 5ustar mbarbonstaffWx-GLCanvas-0.09/Changes0000755000076500000240000000202511240340467014275 0ustar mbarbonstaffRevision history for Perl extension Wx::GLCanvas. 0.09 Tue Aug 11 21:06:05 CEST 2009 - Do not try to autoload DESTROY as if it were a constant. 0.08 Thu Aug 6 20:12:12 CEST 2009 - Add attribute list parameter to wxGLCanvas constructor and wrap WX_GL_* constants. 0.07 Sun Jun 29 21:28:45 CEST 2008 - Try to fail gracefully if wxPerl has not been installed yet. 0.06 Sat Jun 23 22:03:29 CEST 2007 - Compatibility with wxWidgets 2.9.x. 0.05 Sat Nov 11 17:14:03 CET 2006 - Compilation fixes for wxWidgets 2.7.1 and 2.7.2. 0.04 Sun Aug 27 17:38:24 CEST 2006 - Add overloaded Wx::GLCanvas constructors. - Make the cube rotate and have shiny colors. - Use the wxDemo framework for the example. 0.03 Wed Jan 5 07:43:03 CET 2005 - Various fixes for wxWidgets 2.5.3 under Windows. 0.02 Fri Sep 12 23:35:08 CEST 2003 - Compatibility with wxWindows 2.5.x - Don't depend on OpenGL. Any module providing access to OpenGL API can be used together with Wx::GLCanvas. 0.01 Tue Aug 26 16:44:26 CEST 2003 - First version. Wx-GLCanvas-0.09/GLCanvas.xs0000644000076500000240000001376011101424660015013 0ustar mbarbonstaff///////////////////////////////////////////////////////////////////////////// // Name: GLCanvas.xs // Purpose: XSor Wx::GLCanvas.pm // Author: Mattia Barbon // Modified by: // Created: 26/07/2003 // RCS-ID: $Id: GLCanvas.xs 2489 2008-10-27 19:50:51Z mbarbon $ // Copyright: (c) 2003, 2005, 2007-2008 Mattia Barbon // Licence: This program is free software; you can redistribute it and/or // modify it under the same terms as Perl itself ///////////////////////////////////////////////////////////////////////////// #define STRICT #define PERL_NO_GET_CONTEXT #define WXINTL_NO_GETTEXT_MACRO 1 #include #include "wx/window.h" #include "cpp/wxapi.h" #include "cpp/overload.h" #include "cpp/ovl_const.h" #include "cpp/ovl_const.cpp" #undef THIS #if WXPERL_W_VERSION_GE( 2, 5, 0 ) && wxUSE_GLCANVAS #include #else #ifdef __WXMSW__ #undef wxUSE_GLCANVAS #define wxUSE_GLCANVAS 1 #define WXDLLIMPEXP_GL #include "wx/myglcanvas.h" #include "wx/glcanvas.cpp" #else #include #endif #endif int* wxPli_get_attribute_list( pTHX_ SV* avref ) { if( !avref ) return NULL; // special case for empty array if( SvROK( avref ) && SvTYPE( SvRV( avref ) ) == SVt_PVAV && av_len( (AV*) SvRV( avref ) ) == -1 ) return NULL; int* array; wxPli_av_2_intarray( aTHX_ avref, &array ); return array; } static double constant( const char *name, int arg ) { errno = 0; #define r( n ) \ if( strEQ( name, #n ) ) \ return n; switch( name[0] ) { case 'W': r( WX_GL_RGBA ); r( WX_GL_BUFFER_SIZE ); r( WX_GL_LEVEL ); r( WX_GL_DOUBLEBUFFER ); r( WX_GL_STEREO ); r( WX_GL_AUX_BUFFERS ); r( WX_GL_MIN_RED ); r( WX_GL_MIN_GREEN ); r( WX_GL_MIN_BLUE ); r( WX_GL_MIN_ALPHA ); r( WX_GL_DEPTH_SIZE ); r( WX_GL_STENCIL_SIZE ); r( WX_GL_MIN_ACCUM_RED ); r( WX_GL_MIN_ACCUM_GREEN ); r( WX_GL_MIN_ACCUM_BLUE ); r( WX_GL_MIN_ACCUM_ALPHA ); break; default: break; } #undef r errno = EINVAL; return 0; } MODULE=Wx__GLCanvas PACKAGE=Wx::GLCanvas BOOT: INIT_PLI_HELPERS( wx_pli_helpers ); double constant( name, arg ) const char* name int arg ## DECLARE_OVERLOAD( wglx, Wx::GLContext ) ## DECLARE_OVERLOAD( wglc, Wx::GLCanvas ) void wxGLCanvas::new( ... ) PPCODE: BEGIN_OVERLOAD() MATCH_REDISP_COUNT_ALLOWMORE( wxPliOvl_wwin_n_wpoi_wsiz_n_s, newDefault, 1 ) #if WXPERL_W_VERSION_LT( 2, 9, 0 ) MATCH_REDISP_COUNT_ALLOWMORE( wxPliOvl_wwin_wglx_n_wpoi_wsiz_n_s, newContext, 2 ) MATCH_REDISP_COUNT_ALLOWMORE( wxPliOvl_wwin_wglc_n_wpoi_wsiz_n_s, newCanvas, 2 ) #endif END_OVERLOAD( Wx::GLCanvas::new ) static wxGLCanvas* wxGLCanvas::newDefault( parent, id = -1, pos = wxDefaultPosition, size = wxDefaultSize, style = 0, name = wxGLCanvasName, attributes = NULL ) wxWindow* parent wxWindowID id wxPoint pos wxSize size long style wxString name SV_null* attributes CODE: wxPliArrayGuard attrs = wxPli_get_attribute_list( aTHX_ attributes ); #if WXPERL_W_VERSION_GE( 2, 9, 0 ) RETVAL = new wxGLCanvas( parent, id, attrs, pos, size, style, name ); #else RETVAL = new wxGLCanvas( parent, id, pos, size, style, name, attrs ); #endif wxPli_create_evthandler( aTHX_ RETVAL, CLASS ); OUTPUT: RETVAL #if WXPERL_W_VERSION_GE( 2, 9, 0 ) void wxGLCanvas::SetCurrent( context ) wxGLContext* context C_ARGS: *context #else static wxGLCanvas* wxGLCanvas::newContext( parent, context, id = -1, pos = wxDefaultPosition, size = wxDefaultSize, style = 0, name = wxGLCanvasName, attributes = NULL ) wxWindow* parent wxGLContext* context wxWindowID id wxPoint pos wxSize size long style wxString name SV_null* attributes CODE: wxPliArrayGuard attrs = wxPli_get_attribute_list( aTHX_ attributes ); RETVAL = new wxGLCanvas( parent, context, id, pos, size, style, name, attrs ); wxPli_create_evthandler( aTHX_ RETVAL, CLASS ); OUTPUT: RETVAL static wxGLCanvas* wxGLCanvas::newCanvas( parent, canvas, id = -1, pos = wxDefaultPosition, size = wxDefaultSize, style = 0, name = wxGLCanvasName, attributes = NULL ) wxWindow* parent wxGLCanvas* canvas wxWindowID id wxPoint pos wxSize size long style wxString name SV_null* attributes CODE: wxPliArrayGuard attrs = wxPli_get_attribute_list( aTHX_ attributes ); RETVAL = new wxGLCanvas( parent, canvas, id, pos, size, style, name, attrs ); wxPli_create_evthandler( aTHX_ RETVAL, CLASS ); OUTPUT: RETVAL wxGLContext* wxGLCanvas::GetContext() void wxGLCanvas::SetCurrent() #endif #ifdef __WXMSW__ void wxGLCanvas::SetupPalette( palette ) wxPalette* palette CODE: THIS->SetupPalette( *palette ); #endif void wxGLCanvas::SwapBuffers() MODULE=Wx__GLCanvas PACKAGE=Wx::GLContext #if ( WXPERL_W_VERSION_GE( 2, 7, 1 ) && !defined( __WXMAC__ ) ) \ || WXPERL_W_VERSION_GE( 2, 9, 0 ) wxGLContext* wxGLContext::new(win, cxt = NULL ) wxGLCanvas* win wxGLContext* cxt CODE: RETVAL = cxt ? new wxGLContext( win, cxt ) : new wxGLContext( win ); OUTPUT: RETVAL #else #if !defined( __WXMAC__ ) wxGLContext* wxGLContext::new( isRGB, win, palette = (wxPalette*)&wxNullPalette, cxt = NULL ) bool isRGB wxGLCanvas* win wxPalette* palette wxGLContext* cxt CODE: RETVAL = cxt ? new wxGLContext( isRGB, win, *palette, cxt ) : new wxGLContext( isRGB, win, *palette ); OUTPUT: RETVAL #endif #endif #if ( WXPERL_W_VERSION_GE( 2, 7, 1 ) && !defined( __WXMAC__ ) ) \ || WXPERL_W_VERSION_GE( 2, 9, 0 ) void wxGLContext::SetCurrent( wxGLCanvas* canvas ) C_ARGS: *canvas #else void wxGLContext::SetCurrent() void wxGLContext::SwapBuffers() #endif #if WXPERL_W_VERSION_LE( 2, 7, 0 ) void wxGLContext::SetColour( colour ) wxString colour #endif Wx-GLCanvas-0.09/inc/0000755000076500000240000000000011240340556013550 5ustar mbarbonstaffWx-GLCanvas-0.09/inc/MyMakeMaker.pm0000644000076500000240000000133511031641336016251 0ustar mbarbonstaffpackage MyMakeMaker; use strict; use Exporter; *import =\&Exporter::import; our @EXPORT = qw(wxWriteMakefile); eval { require Wx::build::MakeMaker }; my $has_wx = $@ ? 0 : 1; if( !$has_wx ) { require ExtUtils::MakeMaker; ExtUtils::MakeMaker->import; *wxWriteMakefile = sub { my( %args ) = @_; unless( $has_wx ) { $args{depend} = { '$(FIRST_MAKEFILE)' => 'you_better_rebuild_me' }; delete $args{$_} foreach grep /WX_|_WX/, keys %args; } WriteMakefile( %args ); if( !$has_wx ) { sleep 3; open my $fh, ">> you_better_rebuild_me"; print $fh "touched"; } }; } else { Wx::build::MakeMaker->import; } 1; Wx-GLCanvas-0.09/lib/0000755000076500000240000000000011240340556013545 5ustar mbarbonstaffWx-GLCanvas-0.09/lib/Wx/0000755000076500000240000000000011240340556014143 5ustar mbarbonstaffWx-GLCanvas-0.09/lib/Wx/DemoModules/0000755000076500000240000000000011240340556016360 5ustar mbarbonstaffWx-GLCanvas-0.09/lib/Wx/DemoModules/wxGLCanvas.pm0000644000076500000240000002020611101424660020726 0ustar mbarbonstaff############################################################################# ## Name: lib/Wx/DemoModules/wxGLCanvas.pm ## Purpose: wxPerl demo helper for Wx::GLCanvas ## Author: Mattia Barbon ## Modified by: ## Created: 26/07/2003 ## RCS-ID: $Id: wxGLCanvas.pm 2489 2008-10-27 19:50:51Z mbarbon $ ## Copyright: (c) 2000, 2006, 2008 Mattia Barbon ## Licence: This program is free software; you can redistribute it and/or ## modify it under the same terms as Perl itself ############################################################################# package Wx::DemoModules::wxGLCanvas; use strict; use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_IDLE EVT_TIMER); # must load OpenGL *before* Wx::GLCanvas use OpenGL qw(:glconstants :glfunctions); use base qw(Wx::GLCanvas Class::Accessor::Fast); use Wx::GLCanvas qw(:all); __PACKAGE__->mk_accessors( qw(timer x_rot y_rot dirty init) ); sub new { my( $class, $parent ) = @_; my $self = $class->SUPER::new( $parent ); # my $self = $class->SUPER::new( $parent, -1, [-1, -1], [-1, -1], 0, # "GLCanvas", # [WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0] ); my $timer = $self->timer( Wx::Timer->new( $self ) ); $timer->Start( 50 ); $self->x_rot( 0 ); $self->y_rot( 0 ); EVT_PAINT( $self, sub { my $dc = Wx::PaintDC->new( $self ); $self->Render( $dc ); } ); EVT_SIZE( $self, sub { $self->dirty( 1 ) } ); EVT_IDLE( $self, sub { return unless $self->dirty; $self->Resize( $self->GetSizeWH ); $self->Refresh; } ); EVT_TIMER( $self, -1, sub { my( $self, $e ) = @_; $self->x_rot( $self->x_rot - 1 ); $self->y_rot( $self->y_rot + 2 ); $self->dirty( 1 ); Wx::WakeUpIdle; } ); return $self; } sub GetContext { my( $self ) = @_; if( Wx::wxVERSION >= 2.009 ) { return $self->{context} ||= Wx::GLContext->new( $self ); } else { return $self->SUPER::GetContext; } } sub SetCurrent { my( $self, $context ) = @_; if( Wx::wxVERSION >= 2.009 ) { return $self->SUPER::SetCurrent( $context ); } else { return $self->SUPER::SetCurrent; } } sub Resize { my( $self, $x, $y ) = @_; return unless $self->GetContext; $self->dirty( 0 ); $self->SetCurrent( $self->GetContext ); glViewport( 0, 0, $x, $y ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); my_gluPerspective( 45, $x/$y, .5, 100 ); glMatrixMode(GL_MODELVIEW); } use Math::Trig; sub my_gluPerspective { my( $fov, $ratio, $near, $far ) = @_; my $top = tan(deg2rad($fov)*0.5) * $near; my $bottom = -$top; my $left = $ratio * $bottom; my $right = $ratio * $top; glFrustum( $left, $right, $bottom, $top, $near, $far ); } sub DESTROY { my( $self ) = @_; $self->timer->Stop; $self->timer( undef ); } sub tags { [ 'windows/glcanvas' => 'wxGLCanvas' ] } package Wx::DemoModules::wxGLCanvas::Cube; use strict; # must load OpenGL *before* Wx::GLCanvas use OpenGL qw(:glconstants :glfunctions); use base qw(Wx::DemoModules::wxGLCanvas); sub cube { my( @v ) = ( [ 1, 1, 1 ], [ -1, 1, 1 ], [ -1, -1, 1 ], [ 1, -1, 1 ], [ 1, 1, -1 ], [ -1, 1, -1 ], [ -1, -1, -1 ], [ 1, -1, -1 ] ); my( @c ) = ( [ 1, 1, 0 ], [ 1, 0, 1 ], [ 0, 1, 1 ], [ 1, 1, 1 ], [ 0, 0, 1 ], [ 0, 1, 0 ], [ 1, 0, 1 ], [ 1, 1, 0 ] ); my( @s ) = ( [ 0, 1, 2, 3 ], [ 4, 5, 6, 7 ], [ 0, 1, 5, 4 ], [ 2, 3, 7, 6 ], [ 1, 2, 6, 5 ], [ 0, 3, 7, 4 ] ); for my $i ( 0 .. 5 ) { my $s = $s[$i]; glBegin(GL_QUADS); foreach my $j ( @$s ) { glColor3f( @{$c[$j]} ); glVertex3f( @{$v[$j]} ); } glEnd(); } } sub InitGL { my $self = shift; return if $self->init; return unless $self->GetContext; $self->init( 1 ); glDisable( GL_LIGHTING ); glDepthFunc( GL_LESS ); glEnable( GL_DEPTH_TEST ); } sub Render { my( $self, $dc ) = @_; return unless $self->GetContext; $self->SetCurrent( $self->GetContext ); $self->InitGL; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef( 0, 0, -5 ); glRotatef( $self->x_rot, 1, 0, 0 ); glRotatef( $self->y_rot, 0, 0, 1 ); cube(); glPopMatrix(); glFlush(); $self->SwapBuffers(); } sub add_to_tags { qw(windows/glcanvas) } sub title { 'Cube' } sub file { __FILE__ } package Wx::DemoModules::wxGLCanvas::Light; use strict; # must load OpenGL *before* Wx::GLCanvas use OpenGL qw(:glconstants :glfunctions); use base qw(Wx::DemoModules::wxGLCanvas); sub plane_mat { glMaterialfv_p( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, 0.2, 0.1, 0.8, 0.5 ); glMaterialfv_p( GL_FRONT, GL_SPECULAR, 1, 1, 1, 1 ); glMaterialfv_p( GL_FRONT, GL_SHININESS, 4 ); } sub plane { my( $x, $y, $step ) = ( -2, -2, .5 ); for my $i ( 0 .. 7 ) { $x += $step; $y = -2; for my $j ( 0 .. 7 ) { $y += $step; glBegin(GL_QUADS); glNormal3f( 0, 1, 0 ); glVertex3f( $x, -1, $y ); glVertex3f( $x, -1, $y + $step ); glVertex3f( $x + $step, -1, $y + $step ); glVertex3f( $x + $step, -1, $y ); glEnd(); } } } sub icosaedron_mat { glMaterialfv_p( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, 0.1, 0.4, 0.7, 1 ); glMaterialfv_p( GL_FRONT, GL_SPECULAR, 1, 0, 0, 1 ); glMaterialfv_p( GL_FRONT, GL_SHININESS, 5 ); glMaterialfv_p( GL_FRONT, GL_EMISSION, 0.1, 0.2, 0.7, 0 ); } sub icosahedron{ # from the 'light' demo in OpenGL-0.54 # from OpenGL Programming Guide page 56 my $x = 0.525731112119133606; my $z = 0.850650808352039932; my $v=[ [-$x, 0, $z], [ $x, 0, $z], [-$x, 0, -$z], [ $x, 0, -$z], [ 0, $z, $x], [ 0, $z, -$x], [ 0, -$z, $x], [ 0, -$z, -$x], [ $z, $x, 0], [-$z, $x, 0], [ $z, -$x, 0], [-$z, -$x, 0], ]; my $t=[ [0,4,1], [0, 9, 4], [9, 5, 4], [4, 5, 8], [4, 8, 1], [8, 10, 1], [8, 3, 10], [5, 3, 8], [5, 2, 3], [2, 7, 3], [7, 10, 3], [7, 6, 10], [7, 11, 6], [11, 0, 6], [0, 1, 6], [6, 1, 10], [9, 0, 11], [9, 11, 2], [9, 2, 5], [7, 2, 11], ]; for(my $i=0;$i<20;$i++) { glBegin(GL_POLYGON); for(my $j=0;$j<3;$j++) { glNormal3f( $v->[$t->[$i][$j]][0], $v->[$t->[$i][$j]][1], $v->[$t->[$i][$j]][2]); glVertex3f( $v->[$t->[$i][$j]][0], $v->[$t->[$i][$j]][1], $v->[$t->[$i][$j]][2]); } glEnd(); } } sub InitGL { my $self = shift; return if $self->init; return unless $self->GetContext; $self->init( 1 ); glLightfv_p( GL_LIGHT0, GL_AMBIENT, .5,.5,.5,1 ); glLightfv_p( GL_LIGHT0, GL_DIFFUSE, .2,.2,.2,1 ); glLightfv_p( GL_LIGHT0, GL_SPECULAR, 1,.5,.5,1 ); glLightfv_p( GL_LIGHT0, GL_POSITION, -3, 3, -4, 1); glLightfv_p( GL_LIGHT1, GL_SPECULAR, 0, 1, 1, 1 ); glLightfv_p( GL_LIGHT1, GL_POSITION, 0, 0, -6, 1 ); glLightfv_p( GL_LIGHT2, GL_SPECULAR, 1, 1, 1, 1 ); glLightfv_p( GL_LIGHT2, GL_POSITION, 2, -0.5, -4, 1 ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT1 ); glEnable( GL_LIGHT2 ); glDepthFunc( GL_LESS ); glEnable( GL_DEPTH_TEST ); } sub Render { my( $self, $dc ) = @_; return unless $self->GetContext; $self->SetCurrent( $self->GetContext ); $self->InitGL; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); glTranslatef( 0, 0, -5 ); plane_mat(); plane(); glRotatef( $self->x_rot, 1, 0, 0 ); glRotatef( $self->y_rot, 0, 0, 1 ); icosaedron_mat(); icosahedron(); glPopMatrix(); glFlush(); $self->SwapBuffers(); } sub add_to_tags { qw(windows/glcanvas) } sub title { 'Light' } sub file { __FILE__ } 1; Wx-GLCanvas-0.09/lib/Wx/GLCanvas.pm0000644000076500000240000000416211240340072016133 0ustar mbarbonstaff############################################################################# ## Name: lib/Wx/GLCanvas.pm ## Purpose: loader for Wx::GLCanvas.pm ## Author: Mattia Barbon ## Modified by: ## Created: 26/07/2003 ## RCS-ID: $Id: GLCanvas.pm 2489 2008-10-27 19:50:51Z mbarbon $ ## Copyright: (c) 2003, 2005, 2007-2009 Mattia Barbon ## Licence: This program is free software; you can redistribute it and/or ## modify it under the same terms as Perl itself ############################################################################# package Wx::GLCanvas; use strict; use Wx; use base 'Wx::ScrolledWindow'; require Exporter; *import = \&Exporter::import; our @EXPORT_OK = ( qw(WX_GL_RGBA WX_GL_BUFFER_SIZE WX_GL_LEVEL WX_GL_DOUBLEBUFFER WX_GL_STEREO WX_GL_AUX_BUFFERS WX_GL_MIN_RED WX_GL_MIN_GREEN WX_GL_MIN_BLUE WX_GL_MIN_ALPHA WX_GL_DEPTH_SIZE WX_GL_STENCIL_SIZE WX_GL_MIN_ACCUM_RED WX_GL_MIN_ACCUM_GREEN WX_GL_MIN_ACCUM_BLUE WX_GL_MIN_ACCUM_ALPHA) ); our %EXPORT_TAGS = ( all => \@EXPORT_OK, everything => \@EXPORT_OK, ); $Wx::GLCanvas::VERSION = '0.09'; Wx::load_dll( 'gl' ); Wx::wx_boot( 'Wx::GLCanvas', $Wx::GLCanvas::VERSION ); our $AUTOLOAD; sub AUTOLOAD { ( my $constname = $AUTOLOAD ) =~ s<^.*::>{}; return if $constname eq 'DESTROY'; my $val = constant( $constname, 0 ); if( $! != 0 ) { # re-add this if need support for autosplitted subroutines # $AutoLoader::AUTOLOAD = $AUTOLOAD; # goto &AutoLoader::AUTOLOAD; Wx::_croak( "Error while autoloading '$AUTOLOAD'" ); } eval "sub $AUTOLOAD() { $val }"; goto &$AUTOLOAD; } 1; __END__ =head1 NAME Wx::GLCanvas - interface to wxWidgets' OpenGL canvas =head1 SYNOPSIS use OpenGL; # or any other module providing OpenGL API use Wx::GLCanvas; =head1 DESCRIPTION The documentation for this module is included in the main wxPerl distribution (wxGLCanvas). =head1 AUTHOR Mattia Barbon =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut # local variables: # mode: cperl # end: Wx-GLCanvas-0.09/Makefile.PL0000644000076500000240000000325011031761545014754 0ustar mbarbonstaff############################################################################# ## Name: Makefile.PL ## Purpose: Makefile ## Author: Mattia Barbon ## Modified by: ## Created: 26/07/2003 ## RCS-ID: $Id: Makefile.PL 2410 2008-06-29 19:32:37Z mbarbon $ ## Copyright: (c) 2003, 2005, 2007-2008 Mattia Barbon ## Licence: This program is free software; you can redistribute it and/or ## modify it under the same terms as Perl itself ############################################################################# use strict; use lib 'inc'; use MyMakeMaker; my %requires = ( 'Wx' => '0.57', 'Wx::build::MakeMaker' => '0.16', ); eval { require ExtUtils::MY_Metafile; ExtUtils::MY_Metafile->import; my_metafile ( { license => 'perl', dynamic_config => 1, requires => \%requires, build_requires => {}, configure_requires => { 'Wx::build::MakeMaker' => '0.16', }, } ); }; wxWriteMakefile( NAME => 'Wx::GLCanvas', ABSTRACT_FROM => 'lib/Wx/GLCanvas.pm', AUTHOR => 'Mattia Barbon ', VERSION_FROM => 'lib/Wx/GLCanvas.pm', LIBS => ( $^O eq 'MSWin32' ? '-lopengl32' : '' ), WX_CORE_LIB => 'gl core base', WX_OVERLOAD => { header => 'cpp/ovl_const.h', source => 'cpp/ovl_const.cpp', }, PREREQ_PM => \%requires, LICENSE => 'perl', ); Wx-GLCanvas-0.09/MANIFEST0000755000076500000240000000043511240340556014135 0ustar mbarbonstaffChanges GLCanvas.xs MANIFEST Makefile.PL README.txt inc/MyMakeMaker.pm lib/Wx/DemoModules/wxGLCanvas.pm lib/Wx/GLCanvas.pm t/01_load.t t/zz_pod.t typemap wx/glcanvas.cpp wx/msw_myglcanvas.h wx/myglcanvas.h META.yml Module meta-data (added by MakeMaker) Wx-GLCanvas-0.09/META.yml0000644000076500000240000000122711240340556014252 0ustar mbarbonstaff# http://module-build.sourceforge.net/META-spec.html name: Wx-GLCanvas version: 0.09 version_from: lib/Wx/GLCanvas.pm installdirs: site author: Mattia Barbon abstract: interface to wxWidgets' OpenGL canvas license: perl requires: Wx: 0.57 Wx::build::MakeMaker: 0.16 #build_requires: no_index: directory: - inc - t - samples # extras. configure_requires: Wx::build::MakeMaker: 0.16 dynamic_config: 1 distribution_type: module generated_by: ExtUtils::MY_Metafile version 0.09, EUMM-6.54. meta-spec: version: 1.3 url: http://module-build.sourceforge.net/META-spec-v1.3.html Wx-GLCanvas-0.09/README.txt0000755000076500000240000000073610615057254014513 0ustar mbarbonstaffWx::GLCanvas is a wrapper for wxWidgets' OpenGL canvas. Copyright (c) 2003, 2005, 2006 Mattia Barbon. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The files msw_myglcanvas.h, myglcanvas.h and glcanvas.cpp are Copyright (c) Julian Smart, and are distributed under the wxWindows licence (OSI certified, http://www.opensource.org/) INSTALLATION: Build and install wxPerl, then perl Makefile.PL make make install Wx-GLCanvas-0.09/t/0000755000076500000240000000000011240340556013242 5ustar mbarbonstaffWx-GLCanvas-0.09/t/01_load.t0000755000076500000240000000015010615057253014651 0ustar mbarbonstaff#!/usr/bin/perl -w use strict; use Wx; BEGIN { print "1..1\n" } use Wx::GLCanvas; print "ok 1\n"; Wx-GLCanvas-0.09/t/zz_pod.t0000755000076500000240000000031610615057253014743 0ustar mbarbonstaff#!/usr/bin/perl -w use strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; Test::Pod::all_pod_files_ok( Test::Pod::all_pod_files( '.' ) ); Wx-GLCanvas-0.09/typemap0000755000076500000240000000116611101423636014405 0ustar mbarbonstaff############################################################################# ## Name: typemap ## Purpose: typemap for Wx::GLCanvas.pm ## Author: Mattia Barbon ## Modified by: ## Created: 26/07/2003 ## RCS-ID: $Id: typemap,v 1.2 2003/09/12 21:35:54 mbarbon Exp $ ## Copyright: (c) 2003, 2008 Mattia Barbon ## Licence: This program is free software; you can redistribute it and/or ## modify it under the same terms as Perl itself ############################################################################# wxGLCanvas* O_WXEVTHANDLER wxGLContext* O_NON_WXOBJECT Wx-GLCanvas-0.09/wx/0000755000076500000240000000000011240340556013435 5ustar mbarbonstaffWx-GLCanvas-0.09/wx/glcanvas.cpp0000755000076500000240000005024610637276351015763 0ustar mbarbonstaff///////////////////////////////////////////////////////////////////////////// // Name: src/msw/glcanvas.cpp // Purpose: wxGLCanvas, for using OpenGL with wxWindows under MS Windows // Author: Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id: glcanvas.cpp,v 1.1 2006/08/19 18:07:56 mbarbon Exp $ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ #pragma implementation "glcanvas.h" #endif #include "wx/wxprec.h" #if defined(__BORLANDC__) #pragma hdrstop #endif #if wxUSE_GLCANVAS #ifndef WX_PRECOMP #include "wx/frame.h" #include "wx/settings.h" #include "wx/intl.h" #include "wx/log.h" #endif #include "wx/msw/private.h" #include "wx/glcanvas.h" /* The following two compiler directives are specific to the Microsoft Visual C++ family of compilers Fundementally what they do is instruct the linker to use these two libraries for the resolution of symbols. In essence, this is the equivalent of adding these two libraries to either the Makefile or project file. This is NOT a recommended technique, and certainly is unlikely to be used anywhere else in wxWindows given it is so specific to not only wxMSW, but also the VC compiler. However, in the case of opengl support, it's an applicable technique as opengl is optional in setup.h This code (wrapped by wxUSE_GLCANVAS), now allows opengl support to be added purely by modifying setup.h rather than by having to modify either the project or DSP fle. See MSDN for further information on the exact usage of these commands. */ #ifdef _MSC_VER # pragma comment( lib, "opengl32" ) # pragma comment( lib, "glu32" ) #endif static const wxChar *wxGLCanvasClassName = wxT("wxGLCanvasClass"); static const wxChar *wxGLCanvasClassNameNoRedraw = wxT("wxGLCanvasClassNR"); LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); /* * GLContext implementation */ wxGLContext::wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette) { m_window = win; m_hDC = win->GetHDC(); m_glContext = wglCreateContext((HDC) m_hDC); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); wglMakeCurrent((HDC) m_hDC, m_glContext); } wxGLContext::wxGLContext( bool isRGB, wxGLCanvas *win, const wxPalette& palette, const wxGLContext *other /* for sharing display lists */ ) { m_window = win; m_hDC = win->GetHDC(); m_glContext = wglCreateContext((HDC) m_hDC); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); if( other != 0 ) wglShareLists( other->m_glContext, m_glContext ); wglMakeCurrent((HDC) m_hDC, m_glContext); } wxGLContext::~wxGLContext() { if (m_glContext) { wglMakeCurrent(NULL, NULL); wglDeleteContext(m_glContext); } } void wxGLContext::SwapBuffers() { if (m_glContext) { wglMakeCurrent((HDC) m_hDC, m_glContext); ::SwapBuffers((HDC) m_hDC); //blits the backbuffer into DC } } void wxGLContext::SetCurrent() { if (m_glContext) { wglMakeCurrent((HDC) m_hDC, m_glContext); } /* setupPixelFormat(hDC); setupPalette(hDC); */ } void wxGLContext::SetColour(const wxChar *colour) { float r = 0.0; float g = 0.0; float b = 0.0; wxColour *col = wxTheColourDatabase->FindColour(colour); if (col) { r = (float)(col->Red()/256.0); g = (float)(col->Green()/256.0); b = (float)(col->Blue()/256.0); glColor3f( r, g, b); } } /* * wxGLCanvas implementation */ IMPLEMENT_CLASS(wxGLCanvas, wxWindow) BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) EVT_SIZE(wxGLCanvas::OnSize) EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged) EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette) END_EVENT_TABLE() wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name, int *attribList, const wxPalette& palette) : wxWindow() { m_glContext = (wxGLContext*) NULL; bool ret = Create(parent, id, pos, size, style, name); if ( ret ) { SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } m_hDC = (WXHDC) ::GetDC((HWND) GetHWND()); SetupPixelFormat(attribList); SetupPalette(palette); m_glContext = new wxGLContext(TRUE, this, palette); } wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLContext *shared, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name, int *attribList, const wxPalette& palette ) : wxWindow() { m_glContext = (wxGLContext*) NULL; bool ret = Create(parent, id, pos, size, style, name); if ( ret ) { SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } m_hDC = (WXHDC) ::GetDC((HWND) GetHWND()); SetupPixelFormat(attribList); SetupPalette(palette); m_glContext = new wxGLContext(TRUE, this, palette, shared ); } // Not very useful for wxMSW, but this is to be wxGTK compliant wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name, int *attribList, const wxPalette& palette ): wxWindow() { m_glContext = (wxGLContext*) NULL; bool ret = Create(parent, id, pos, size, style, name); if ( ret ) { SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } m_hDC = (WXHDC) ::GetDC((HWND) GetHWND()); SetupPixelFormat(attribList); SetupPalette(palette); wxGLContext *sharedContext=0; if (shared) sharedContext=shared->GetContext(); m_glContext = new wxGLContext(TRUE, this, palette, sharedContext ); } wxGLCanvas::~wxGLCanvas() { if (m_glContext) delete m_glContext; ::ReleaseDC((HWND) GetHWND(), (HDC) m_hDC); } // Replaces wxWindow::Create functionality, since we need to use a different // window class bool wxGLCanvas::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { static bool s_registeredGLCanvasClass = FALSE; // We have to register a special window class because we need // the CS_OWNDC style for GLCanvas. /* From Angel Popov Here are two snips from a dicussion in the OpenGL Gamedev list that explains how this problem can be fixed: "There are 5 common DCs available in Win95. These are aquired when you call GetDC or GetDCEx from a window that does _not_ have the OWNDC flag. OWNDC flagged windows do not get their DC from the common DC pool, the issue is they require 800 bytes each from the limited 64Kb local heap for GDI." "The deal is, if you hold onto one of the 5 shared DC's too long (as GL apps do), Win95 will actually "steal" it from you. MakeCurrent fails, apparently, because Windows re-assigns the HDC to a different window. The only way to prevent this, the only reliable means, is to set CS_OWNDC." */ if (!s_registeredGLCanvasClass) { WNDCLASS wndclass; // the fields which are common to all classes wndclass.lpfnWndProc = (WNDPROC)wxWndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for? wndclass.hInstance = wxhInstance; wndclass.hIcon = (HICON) NULL; wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW); wndclass.lpszMenuName = NULL; // Register the GLCanvas class name wndclass.hbrBackground = (HBRUSH)NULL; wndclass.lpszClassName = wxGLCanvasClassName; wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC; if ( !::RegisterClass(&wndclass) ) { wxLogLastError(wxT("RegisterClass(wxGLCanvasClass)")); return FALSE; } // Register the GLCanvas class name for windows which don't do full repaint // on resize wndclass.lpszClassName = wxGLCanvasClassNameNoRedraw; wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW); if ( !::RegisterClass(&wndclass) ) { wxLogLastError(wxT("RegisterClass(wxGLCanvasClassNameNoRedraw)")); ::UnregisterClass(wxGLCanvasClassName, wxhInstance); return FALSE; } s_registeredGLCanvasClass = TRUE; } wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") ); if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; parent->AddChild(this); DWORD msflags = 0; /* A general rule with OpenGL and Win32 is that any window that will have a HGLRC built for it must have two flags: WS_CLIPCHILDREN & WS_CLIPSIBLINGS. You can find references about this within the knowledge base and most OpenGL books that contain the wgl function descriptions. */ WXDWORD exStyle = 0; msflags |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; msflags |= MSWGetStyle(style, & exStyle) ; return MSWCreate(wxGLCanvasClassName, NULL, pos, size, msflags, exStyle); } static void AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, int *attribList) { if (attribList) { pfd.dwFlags &= ~PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_COLORINDEX; pfd.cColorBits = 0; int arg=0; while( (attribList[arg]!=0) ) { switch( attribList[arg++] ) { case WX_GL_RGBA: pfd.iPixelType = PFD_TYPE_RGBA; break; case WX_GL_BUFFER_SIZE: pfd.cColorBits = attribList[arg++]; break; case WX_GL_LEVEL: // this member looks like it may be obsolete if (attribList[arg] > 0) { pfd.iLayerType = (BYTE)PFD_OVERLAY_PLANE; } else if (attribList[arg] < 0) { pfd.iLayerType = (BYTE)PFD_UNDERLAY_PLANE; } else { pfd.iLayerType = (BYTE)PFD_MAIN_PLANE; } arg++; break; case WX_GL_DOUBLEBUFFER: pfd.dwFlags |= PFD_DOUBLEBUFFER; break; case WX_GL_STEREO: pfd.dwFlags |= PFD_STEREO; break; case WX_GL_AUX_BUFFERS: pfd.cAuxBuffers = attribList[arg++]; break; case WX_GL_MIN_RED: pfd.cColorBits += (pfd.cRedBits = attribList[arg++]); break; case WX_GL_MIN_GREEN: pfd.cColorBits += (pfd.cGreenBits = attribList[arg++]); break; case WX_GL_MIN_BLUE: pfd.cColorBits += (pfd.cBlueBits = attribList[arg++]); break; case WX_GL_MIN_ALPHA: // doesn't count in cColorBits pfd.cAlphaBits = attribList[arg++]; break; case WX_GL_DEPTH_SIZE: pfd.cDepthBits = attribList[arg++]; break; case WX_GL_STENCIL_SIZE: pfd.cStencilBits = attribList[arg++]; break; case WX_GL_MIN_ACCUM_RED: pfd.cAccumBits += (pfd.cAccumRedBits = attribList[arg++]); break; case WX_GL_MIN_ACCUM_GREEN: pfd.cAccumBits += (pfd.cAccumGreenBits = attribList[arg++]); break; case WX_GL_MIN_ACCUM_BLUE: pfd.cAccumBits += (pfd.cAccumBlueBits = attribList[arg++]); break; case WX_GL_MIN_ACCUM_ALPHA: pfd.cAccumBits += (pfd.cAccumAlphaBits = attribList[arg++]); break; default: break; } } } } void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC) { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), /* size */ 1, /* version */ PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER, /* support double-buffering */ PFD_TYPE_RGBA, /* color type */ 16, /* prefered color depth */ 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ 0, /* no alpha buffer */ 0, /* alpha bits (ignored) */ 0, /* no accumulation buffer */ 0, 0, 0, 0, /* accum bits (ignored) */ 16, /* depth buffer */ 0, /* no stencil buffer */ 0, /* no auxiliary buffers */ PFD_MAIN_PLANE, /* main layer */ 0, /* reserved */ 0, 0, 0, /* no layer, visible, damage masks */ }; AdjustPFDForAttributes(pfd, attribList); int pixelFormat = ChoosePixelFormat((HDC) m_hDC, &pfd); if (pixelFormat == 0) { wxLogLastError(_T("ChoosePixelFormat")); } else { if ( !::SetPixelFormat((HDC) m_hDC, pixelFormat, &pfd) ) { wxLogLastError(_T("SetPixelFormat")); } } } void wxGLCanvas::SetupPalette(const wxPalette& palette) { int pixelFormat = GetPixelFormat((HDC) m_hDC); PIXELFORMATDESCRIPTOR pfd; DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); if (pfd.dwFlags & PFD_NEED_PALETTE) { } else { return; } m_palette = palette; if ( !m_palette.Ok() ) { m_palette = CreateDefaultPalette(); } if (m_palette.Ok()) { SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), FALSE); RealizePalette((HDC) m_hDC); } } wxPalette wxGLCanvas::CreateDefaultPalette() { PIXELFORMATDESCRIPTOR pfd; int paletteSize; int pixelFormat = GetPixelFormat((HDC) m_hDC); DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); paletteSize = 1 << pfd.cColorBits; LOGPALETTE* pPal = (LOGPALETTE*) malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY)); pPal->palVersion = 0x300; pPal->palNumEntries = paletteSize; /* build a simple RGB color palette */ { int redMask = (1 << pfd.cRedBits) - 1; int greenMask = (1 << pfd.cGreenBits) - 1; int blueMask = (1 << pfd.cBlueBits) - 1; int i; for (i=0; ipalPalEntry[i].peRed = (((i >> pfd.cRedShift) & redMask) * 255) / redMask; pPal->palPalEntry[i].peGreen = (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask; pPal->palPalEntry[i].peBlue = (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask; pPal->palPalEntry[i].peFlags = 0; } } HPALETTE hPalette = CreatePalette(pPal); free(pPal); wxPalette palette; palette.SetHPALETTE((WXHPALETTE) hPalette); return palette; } void wxGLCanvas::SwapBuffers() { if (m_glContext) m_glContext->SwapBuffers(); } void wxGLCanvas::OnSize(wxSizeEvent& event) { } void wxGLCanvas::SetCurrent() { if (m_glContext) { m_glContext->SetCurrent(); } } void wxGLCanvas::SetColour(const wxChar *colour) { if (m_glContext) m_glContext->SetColour(colour); } // TODO: Have to have this called by parent frame (?) // So we need wxFrame to call OnQueryNewPalette for all children... void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event) { /* realize palette if this is the current window */ if ( GetPalette()->Ok() ) { ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE()); ::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE); ::RealizePalette((HDC) GetHDC()); Refresh(); event.SetPaletteRealized(TRUE); } else event.SetPaletteRealized(FALSE); } // I think this doesn't have to be propagated to child windows. void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event) { /* realize palette if this is *not* the current window */ if ( GetPalette() && GetPalette()->Ok() && (this != event.GetChangedWindow()) ) { ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE()); ::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE); ::RealizePalette((HDC) GetHDC()); Refresh(); } } /* Give extensions proper function names. */ /* EXT_vertex_array */ void glArrayElementEXT(GLint i) { } void glColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer) { } void glDrawArraysEXT(GLenum mode, GLint first, GLsizei count) { #ifdef GL_EXT_vertex_array static PFNGLDRAWARRAYSEXTPROC proc = 0; if ( !proc ) { proc = (PFNGLDRAWARRAYSEXTPROC) wglGetProcAddress("glDrawArraysEXT"); } if ( proc ) (* proc) (mode, first, count); #endif } void glEdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *pointer) { } void glGetPointervEXT(GLenum pname, GLvoid* *params) { } void glIndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer) { } void glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer) { #ifdef GL_EXT_vertex_array static PFNGLNORMALPOINTEREXTPROC proc = 0; if ( !proc ) { proc = (PFNGLNORMALPOINTEREXTPROC) wglGetProcAddress("glNormalPointerEXT"); } if ( proc ) (* proc) (type, stride, count, pointer); #endif } void glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer) { } void glVertexPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer) { #ifdef GL_EXT_vertex_array static PFNGLVERTEXPOINTEREXTPROC proc = 0; if ( !proc ) { proc = (PFNGLVERTEXPOINTEREXTPROC) wglGetProcAddress("glVertexPointerEXT"); } if ( proc ) (* proc) (size, type, stride, count, pointer); #endif } /* EXT_color_subtable */ void glColorSubtableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *table) { } /* EXT_color_table */ void glColorTableEXT(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table) { } void glCopyColorTableEXT(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) { } void glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid *table) { } void glGetColorTableParamaterfvEXT(GLenum target, GLenum pname, GLfloat *params) { } void glGetColorTavleParameterivEXT(GLenum target, GLenum pname, GLint *params) { } /* SGI_compiled_vertex_array */ void glLockArraysSGI(GLint first, GLsizei count) { } void glUnlockArraysSGI() { } /* SGI_cull_vertex */ void glCullParameterdvSGI(GLenum pname, GLdouble* params) { } void glCullParameterfvSGI(GLenum pname, GLfloat* params) { } /* SGI_index_func */ void glIndexFuncSGI(GLenum func, GLclampf ref) { } /* SGI_index_material */ void glIndexMaterialSGI(GLenum face, GLenum mode) { } /* WIN_swap_hint */ void glAddSwapHintRectWin(GLint x, GLint y, GLsizei width, GLsizei height) { } //--------------------------------------------------------------------------- // wxGLApp //--------------------------------------------------------------------------- IMPLEMENT_CLASS(wxGLApp, wxApp) bool wxGLApp::InitGLVisual(int *attribList) { int pixelFormat; PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), /* size */ 1, /* version */ PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER, /* support double-buffering */ PFD_TYPE_RGBA, /* color type */ 16, /* prefered color depth */ 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ 0, /* no alpha buffer */ 0, /* alpha bits (ignored) */ 0, /* no accumulation buffer */ 0, 0, 0, 0, /* accum bits (ignored) */ 16, /* depth buffer */ 0, /* no stencil buffer */ 0, /* no auxiliary buffers */ PFD_MAIN_PLANE, /* main layer */ 0, /* reserved */ 0, 0, 0, /* no layer, visible, damage masks */ }; AdjustPFDForAttributes(pfd, attribList); // use DC for whole (root) screen, since no windows have yet been created pixelFormat = ChoosePixelFormat(ScreenHDC(), &pfd); if (pixelFormat == 0) { wxLogError(wxGetTranslation(wxT("Failed to initialize OpenGL"))); return FALSE; } return TRUE; } wxGLApp::~wxGLApp() { } #endif // wxUSE_GLCANVAS Wx-GLCanvas-0.09/wx/msw_myglcanvas.h0000755000076500000240000001167510637276351016667 0ustar mbarbonstaff///////////////////////////////////////////////////////////////////////////// // Name: wx/msw/glcanvas.h // Purpose: wxGLCanvas, for using OpenGL with wxWindows under Windows // Author: Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id: msw_myglcanvas.h,v 1.1 2006/08/19 18:07:56 mbarbon Exp $ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ #pragma interface "glcanvas.h" #endif #ifndef _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_ #include "wx/palette.h" #include "wx/scrolwin.h" #include #include "wx/msw/winundef.h" #include //--------------------------------------------------------------------------- // Constants for attriblist //--------------------------------------------------------------------------- // The generic GL implementation doesn't support most of these options, // such as stereo, auxiliary buffers, alpha channel, and accum buffer. // Other implementations may actually support them. enum { WX_GL_RGBA=1, /* use true color palette */ WX_GL_BUFFER_SIZE, /* bits for buffer if not WX_GL_RGBA */ WX_GL_LEVEL, /* 0 for main buffer, >0 for overlay, <0 for underlay */ WX_GL_DOUBLEBUFFER, /* use doublebuffer */ WX_GL_STEREO, /* use stereoscopic display */ WX_GL_AUX_BUFFERS, /* number of auxiliary buffers */ WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */ WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */ WX_GL_MIN_BLUE, /* use blue buffer with most bits (> MIN_BLUE bits) */ WX_GL_MIN_ALPHA, /* use blue buffer with most bits (> MIN_ALPHA bits) */ WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */ WX_GL_STENCIL_SIZE, /* bits for stencil buffer */ WX_GL_MIN_ACCUM_RED, /* use red accum buffer with most bits (> MIN_ACCUM_RED bits) */ WX_GL_MIN_ACCUM_GREEN, /* use green buffer with most bits (> MIN_ACCUM_GREEN bits) */ WX_GL_MIN_ACCUM_BLUE, /* use blue buffer with most bits (> MIN_ACCUM_BLUE bits) */ WX_GL_MIN_ACCUM_ALPHA /* use blue buffer with most bits (> MIN_ACCUM_ALPHA bits) */ }; class WXDLLIMPEXP_GL wxGLCanvas; /* forward reference */ class WXDLLIMPEXP_GL wxGLContext: public wxObject { public: wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette = wxNullPalette); wxGLContext( bool isRGB, wxGLCanvas *win, const wxPalette& WXUNUSED(palette), const wxGLContext *other /* for sharing display lists */ ); ~wxGLContext(); void SetCurrent(); void SetColour(const wxChar *colour); void SwapBuffers(); inline wxWindow* GetWindow() const { return m_window; } inline WXHDC GetHDC() const { return m_hDC; } inline HGLRC GetGLRC() const { return m_glContext; } public: HGLRC m_glContext; WXHDC m_hDC; wxWindow* m_window; }; class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow { DECLARE_CLASS(wxGLCanvas) public: wxGLCanvas(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxGLCanvasName, int *attribList = 0, const wxPalette& palette = wxNullPalette); wxGLCanvas( wxWindow *parent, const wxGLContext *shared = (wxGLContext *)NULL, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxGLCanvasName, int *attribList = (int*) NULL, const wxPalette& palette = wxNullPalette ); wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared = (wxGLCanvas *)NULL, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxGLCanvasName, int *attribList = 0, const wxPalette& palette = wxNullPalette ); ~wxGLCanvas(); // Replaces wxWindow::Create functionality, since we need to use a different window class bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name); void SetCurrent(); void SetColour(const wxChar *colour); void SwapBuffers(); void OnSize(wxSizeEvent& event); void OnQueryNewPalette(wxQueryNewPaletteEvent& event); void OnPaletteChanged(wxPaletteChangedEvent& event); inline wxGLContext* GetContext() const { return m_glContext; } inline WXHDC GetHDC() const { return m_hDC; } void SetupPixelFormat(int *attribList = (int*) NULL); void SetupPalette(const wxPalette& palette); wxPalette CreateDefaultPalette(); inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; } protected: wxGLContext* m_glContext; // this is typedef-ed ptr, in fact wxPalette m_palette; WXHDC m_hDC; DECLARE_EVENT_TABLE() }; #endif // _WX_GLCANVAS_H_ Wx-GLCanvas-0.09/wx/myglcanvas.h0000755000076500000240000000166710615057254015774 0ustar mbarbonstaff#ifndef _WX_GLCANVAS_H_BASE_ #define _WX_GLCANVAS_H_BASE_ #include "wx/defs.h" #if wxUSE_GLCANVAS #define wxGLCanvasName _T("GLCanvas") #if defined(__WXMSW__) #include "wx/msw_myglcanvas.h" #elif defined(__WXMOTIF__) #include "wx/x11/glcanvas.h" #elif defined(__WXGTK__) #include "wx/gtk/glcanvas.h" #elif defined(__WXX11__) #include "wx/x11/glcanvas.h" #elif defined(__WXMAC__) #include "wx/mac/glcanvas.h" #elif defined(__WXPM__) #include "wx/os2/glcanvas.h" #endif #include "wx/app.h" class WXDLLIMPEXP_GL wxGLApp : public wxApp { public: wxGLApp() : wxApp() { } virtual ~wxGLApp(); // use this in the constructor of the user-derived wxGLApp class to // determine if an OpenGL rendering context with these attributes // is available - returns TRUE if so, FALSE if not. bool InitGLVisual(int *attribList); private: DECLARE_DYNAMIC_CLASS(wxGLApp) }; #endif // wxUSE_GLCANVAS #endif // _WX_GLCANVAS_H_BASE_