Hi
here is an example using the new Win32-GUI-OpenGLFrame , it is displaying
either a rotating triangle or a rotating cube when you click an appropriate
button.
yes thanks , i am sure this addition will be used heavily when the people
know about it.
here is the downloadable example:
http://rapidshare.com/files/256462790/cube_Triangle.pl

#!perl -w
use strict;
use warnings;
use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::OpenGLFrame qw(w32gSwapBuffers);
use OpenGL qw(:all);
my $spin = 0.0;
my $toggle = 0;
my $xrot = 0;
my $yrot = 0;
my $rtri  = 0.0;
my $rtcube = 0.0;
my $objectXRot = 0.0;
my $objectYRot = 0.0;
my $objectZRot = 0.0;
my $flag = 1;
my $mw = Win32::GUI::Window->new(
 -title => "OpenGL Demonstration",
 -pos   => [0,0],
 -size  => [640,480],
 -pushstyle => WS_CLIPCHILDREN,  # stop flickering on resize
 -onResize  => \&mainWinResize,
);
my $glw = $mw->AddOpenGLFrame(
 -name    => 'oglwin',
 -width   => $mw->ScaleWidth(),
 -height  => $mw->ScaleHeight() - 50,
 -display => \&display,
 -init    => \&Init,
 -reshape => \&reshape,
 -doubleBuffer => 1,
);

$mw->AddButton(
 -name => 'button1',
 -text => 'Triangle',
 -left => $mw->ScaleWidth()-100,
 -top  => $mw->ScaleHeight()-30,
 #-onClick => sub{-1},
);
$mw->AddButton(
 -name => 'button2',
 -text => 'Cube',
 -left => $mw->ScaleWidth()-140,
 -top  => $mw->ScaleHeight()-30,
 #-onClick => sub{-1},

);
$mw->Show();
while(Win32::GUI::DoEvents() != -1) {

    $mw->oglwin->InvalidateRect(0);
}
#Win32::GUI::Dialog();
$mw->Hide();
exit(0);
sub mainWinResize {
 my $win = shift;
 $win->oglwin->Resize($win->ScaleWidth(), $win->ScaleHeight()-50);
 $win->button1->Move($win->ScaleWidth()-100, $win->ScaleHeight()-30);
 $win->button2->Move($win->ScaleWidth()-160, $win->ScaleHeight()-30);
 return 0;
}
sub reshape {
 my ($w, $h) = @_;
 glViewport(0, 0, $w, $h);
 glMatrixMode (GL_PROJECTION);
 glLoadIdentity (); #  define the projection
 gluPerspective(45.0, $h ? $w/$h : 0, 1.0, 20.0);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 return 0;
}
sub Init {
    glShadeModel(GL_SMOOTH);
    glClearColor(0, 0, 0, 0);
    glClearDepth(1);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    return 1;
}
sub display {
 glPushMatrix(); #save current matrix
    if ($flag == 1){DrawTriangle();} #draw triangle
    elsif ($flag == 2){DrawCube();}; #draw cube
    glPopMatrix(); #restore matrix
 glFlush();
    w32gSwapBuffers();
    return 1;
}
sub DrawTriangle {
 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -6.0);
    glRotatef($rtri, 0, 1, 0);
    my $size = 1;
    glScalef($size,$size,$size);
    glBegin(GL_TRIANGLES);
        glColor3f(1.0, 0.0, 0.0);
        glVertex3f(0.0, 1.0, 0.0);
        glColor3f(0.0, 1.0, 0.0);
     glVertex3f(-1.0, -1.0, 0.0);
        glColor3f(0.0, 0.0, 1.0);
     glVertex3f(1.0, -1.0, 0.0);
    glEnd();
    $rtri += 2;
             }
sub DrawCube {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  my $size = 1;
  glTranslatef(0.0, 0.0, -6.0);
  glRotatef($objectXRot, 1.0, 0.0, 0.0);
  glRotatef($objectYRot, 0.0, 1.0, 0.0);
  glRotatef($objectZRot, 0.0, 0.0, 1.0);

  glScalef($size,$size,$size);
  glBegin(GL_QUADS);
   # bottom face
   glColor3f(0.0,0.0,0.0);    #black
   glVertex3f(-1.0,-1.0,-1.0);
   glColor3f(1.0,0.0,0.0);    #red
   glVertex3f(1.0,-1.0,-1.0);
   glColor3f(1.0,0.0,1.0);    #magenta
   glVertex3f(1.0,-1.0,1.0);
   glColor3f(0.0,0.0,1.0);    #blue
   glVertex3f(-1.0,-1.0,1.0);
   # front face
   glColor3f(0.0,0.0,0.0);    #black
   glVertex3f(-1.0,-1.0,-1.0);
   glColor3f(0.0,1.0,0.0);    #green
   glVertex3f(-1.0,1.0,-1.0);
   glColor3f(1.0,1.0,0.0);    #yellow
   glVertex3f(1.0,1.0,-1.0);
   glColor3f(1.0,0.0,0.0);    #red
   glVertex3f(1.0,-1.0,-1.0);
   # right face
   glColor3f(0.0,0.0,0.0);    #black
   glVertex3f(-1.0, -1.0, -1.0);
   glColor3f(0.0,0.0,1.0);    #blue
   glVertex3f(-1.0,-1.0,1.0);
   glColor3f(0.0,1.0,1.0);    #cyan
   glVertex3f(-1.0,1.0,1.0);
   glColor3f(0.0,1.0,0.0);    #green
   glVertex3f(-1.0,1.0,-1.0);
   # left face
   glColor3f(1.0,1.0,1.0);    #white
   glVertex3f(1.0,1.0,1.0);
   glColor3f(1.0,0.0,1.0);    #magenta
   glVertex3f(1.0,-1.0,1.0);
   glColor3f(1.0,0.0,0.0);    #red
   glVertex3f(1.0,-1.0,-1.0);
   glColor3f(1.0,1.0,0.0);    #yellow
   glVertex3f(1.0,1.0,-1.0);
   # top face
   glColor3f(1.0,1.0,1.0);    #white
   glVertex3f(1.0,1.0,1.0);
   glColor3f(1.0,1.0,0.0);    #yelllow
   glVertex3f(1.0,1.0,-1.0);
   glColor3f(0.0,1.0,0.0);    #green
   glVertex3f(-1.0,1.0,-1.0);
   glColor3f(0.0,1.0,1.0);    #cyan
   glVertex3f(-1.0,1.0,1.0);
   # back face
   glColor3f(1.0,1.0,1.0);    #white
   glVertex3f(1.0,1.0,1.0);
   glColor3f(0.0,1.0,1.0);    #cyan
   glVertex3f(-1.0,1.0,1.0);
   glColor3f(0.0,0.0,1.0);    #blue
   glVertex3f(-1.0,-1.0,1.0);
   glColor3f(1.0,0.0,1.0);    #magenta
   glVertex3f(1.0,-1.0,1.0);

  glEnd();
  $objectXRot += 0.5;
  $objectYRot += 0.5;
  $objectZRot += 0.5;

  }
sub button1_Click {
  $flag = 1;
 }

 sub button2_Click {
  $flag = 2;
 }
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to