#!/usr/bin/perl -w use strict; use warnings; use OpenGL qw/ :all /; use constant R30D => 0.523598776; eval {glutInit(); 1} or die qq { This requires GLUT. }; glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA); glutInitWindowSize(500, 500); my $Window_ID = glutCreateWindow( "Open Gl Window" ); # Register the callback function to do the drawing. glutDisplayFunc(\&cbRenderScene); # If there's nothing to do, draw. glutIdleFunc(\&cbRenderScene); # It's a good idea to know when our window's resized. glutReshapeFunc(\&resizeEvent); # And let's get some input. # glutKeyboardFunc(\&cbKeyPressed); # glutSpecialFunc(\&cbSpecialKeyPressed); # glutPassiveMotionFunc(\&mouseMove); # glutMotionFunc(\&mouseMove); # glutMouseFunc(\&mouseClick); # Pass off control to OpenGL. # Above functions are called as appropriate. glutMainLoop(); exit 0; sub resizeEvent { my ($Width, $Height) = @_; print "Resize: $Width, $Height\n"; # Let's not core dump, no matter what. $Height = 1 if ($Height <1); glViewport(0, 0, $Width, $Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,$Width/$Height,0.1,100.0); glMatrixMode(GL_MODELVIEW); $main::window_Width = $Width; $main::window_Height = $Height; } sub cbRenderScene { eval {do 'drawframe.pl';}; print $@ . "\r"; # Take a quick nap to avoid wasting CPU select (undef,undef,undef,0.1); }