Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
# @model, # Model Matrix
# @projection, # Projection Matrix
# @viewport); # Viewport
# print "Window point: $point[0], $point[1], $point[2]\n";
print "\n";
}
$idleTime = $hasHires ? gettimeofday() : time();
}
sub GetKeyModifier
{
return $key_mods->{glutGetModifiers()};
}
# ------
# Callback routine executed whenever our window is resized. Lets us
# request the newly appropriate perspective projection matrix for
# our needs. Try removing the gluPerspective() call to see what happens.
sub cbResizeScene
{
my($Width, $Height) = @_;
# Let's not core dump, no matter what.
$Height = 1 if ($Height == 0);
glViewport(0, 0, $Width, $Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,$Width/$Height,0.1,100.0);
glMatrixMode(GL_MODELVIEW);
$Window_Width = $Width;
$Window_Height = $Height;
$idleTime = $hasHires ? gettimeofday() : time();
}
sub cbWindowStat
{
my($stat) = @_;
print "Window status: $stat\n";
}
sub cbClose
{
my($wid) = @_;
print "User has closed window: \#$wid\n";
ReleaseResources();
}
# this is a little complicated
# Using freeglut, doing a straight exit crashes on some systems, mostly observed
# on windows, likely due to thread issues.
# However on non-freeglut systems the proper way of using glutLeaveMainLoop is
# not available.
# So the proper one needs to be chosen.
# However while exit exits the thread, glutLeaveMainLoop only sets a flag for
# the event loop, thus we must take care to return when using it. Additionally
# any use of quit() ALSO needs to return.
#
# return quit();
#
sub quit {
my ($context) = @_;
$context ||= "<unknown context>";
print "Exiting in $context using ";
if (Acme::MITHALDU::BleedingOpenGL::_have_freeglut()) {
print "glutLeaveMainLoop (freeglut)\n";
glutLeaveMainLoop();
return;
}
print "perl exit(0)\n";
exit(0);
}
# ------
# The main() function. Inits OpenGL. Calls our own init function,
# then passes control onto OpenGL.
# Initialize GLUT/FreeGLUT
glutInit();
# To see OpenGL drawing, take out the GLUT_DOUBLE request.
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
if ($^O ne 'MSWin32' and $Acme::MITHALDU::BleedingOpenGL::Config->{DEFINE} !~ /-DHAVE_W32API/) { # skip these MODE checks on win32, they don't work
if (not glutGet(GLUT_DISPLAY_MODE_POSSIBLE))
{
warn "glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA) not possible";
warn "...trying without GLUT_ALPHA";
# try without GLUT_ALPHA
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
if (not glutGet(GLUT_DISPLAY_MODE_POSSIBLE))
{
warn "glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) not possible, exiting quietly";
exit 0;
}
}
}
#glutInitDisplayString("rgb alpha>=0 double depth");
# Open Window
if (defined($gameMode) && glutGameModeString($gameMode))
{
print "Running in Game Mode $gameMode\n";
glutGameModeString($gameMode);
$Window_ID = glutEnterGameMode();
$Window_Width = glutGameModeGet( GLUT_GAME_MODE_WIDTH );
$Window_Height = glutGameModeGet( GLUT_GAME_MODE_HEIGHT );
}
else
{
glutInitWindowSize($Window_Width, $Window_Height);
$Window_ID = glutCreateWindow( PROGRAM_TITLE );
( run in 1.974 second using v1.01-cache-2.11-cpan-140bd7fdf52 )