|
7 | 7 | use OpenGL qw/
|
8 | 8 | :glconstants
|
9 | 9 | glpHasGLUT glpCheckExtension glpFullScreen glpRestoreScreen
|
10 |
| - glGetString glGetError |
| 10 | + glGetString glGetError glpErrorString |
11 | 11 | glGenTextures_p glBindTexture glTexParameteri glTexImage2D_c glTexEnvf
|
12 | 12 | glDeleteTextures_p
|
13 | 13 | glGenerateMipmapEXT
|
|
25 | 25 | glTranslatef glRotatef
|
26 | 26 | glColor3f glColor4f
|
27 | 27 | glPushMatrix glPopMatrix glPushAttrib glPopAttrib
|
28 |
| - glOrtho |
| 28 | + glOrtho glFrustum |
29 | 29 | glRasterPos2i glRasterPos2f
|
30 | 30 | glPixelZoom glReadPixels_c glDrawPixels_c
|
31 | 31 | glGetDoublev_c glGetIntegerv_c
|
|
34 | 34 | use OpenGL::GLUT qw/
|
35 | 35 | :constants :functions
|
36 | 36 | /;
|
37 |
| -use OpenGL::GLU qw/ |
38 |
| - gluBuild2DMipmaps_c gluErrorString |
39 |
| - gluOrtho2D gluProject_p gluUnProject_p gluPerspective |
40 |
| -/; |
41 | 37 | use OpenGL::Config; # for build information
|
42 | 38 |
|
43 | 39 | eval 'use OpenGL::Image 1.03'; # Need to use OpenGL::Image 1.03 or higher!
|
@@ -582,18 +578,27 @@ sub ourBuildTextures
|
582 | 578 | }
|
583 | 579 | glBindTexture(GL_TEXTURE_2D, $TextureID_image);
|
584 | 580 |
|
585 |
| - # Use MipMap |
586 |
| - print "Using Mipmap\n"; |
587 |
| - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, |
588 |
| - GL_NEAREST); |
589 |
| - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
590 |
| - GL_NEAREST_MIPMAP_LINEAR); |
591 |
| - # The GLU library helps us build MipMaps for our texture. |
592 |
| - if (($gluerr = gluBuild2DMipmaps_c(GL_TEXTURE_2D, $Tex_Type, |
593 |
| - $Tex_Width, $Tex_Height, $Tex_Format, $Tex_Size, |
594 |
| - $Tex_Pixels->ptr()))) |
595 |
| - { |
596 |
| - die sprintf "GLULib%s\n", gluErrorString($gluerr); |
| 581 | + if ($hasFBO) { |
| 582 | + # Use MipMap |
| 583 | + print "Using Mipmap\n"; |
| 584 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, |
| 585 | + GL_NEAREST); |
| 586 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 587 | + GL_NEAREST_MIPMAP_LINEAR); |
| 588 | + } else { |
| 589 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 590 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 591 | + } |
| 592 | + glTexImage2D_c(GL_TEXTURE_2D, 0, $Tex_Type, |
| 593 | + $Tex_Width, $Tex_Height, |
| 594 | + 0, $Tex_Format, $Tex_Size, $Tex_Pixels->ptr); |
| 595 | + glGenerateMipmapEXT(GL_TEXTURE_2D) if $hasFBO; |
| 596 | + if ($^O ne 'MSWin32') { |
| 597 | + my $errors = ''; |
| 598 | + while((my $err = glGetError()) != 0) { |
| 599 | + $errors .= "glError: " . glpErrorString($err) . "\n"; |
| 600 | + } |
| 601 | + die $errors if $errors; |
597 | 602 | }
|
598 | 603 |
|
599 | 604 | # Benchmarks for Image Loading
|
@@ -679,7 +684,7 @@ sub ourBuildTextures
|
679 | 684 |
|
680 | 685 | # Test status
|
681 | 686 | my $stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
682 |
| - die "FBO Status error: " . gluErrorString(glGetError()) if !$stat; |
| 687 | + die "FBO Status error: " . glpErrorString(glGetError()) if !$stat; |
683 | 688 | die sprintf "FBO Status: %04X", $stat if $stat != GL_FRAMEBUFFER_COMPLETE_EXT;
|
684 | 689 | }
|
685 | 690 |
|
@@ -1065,7 +1070,7 @@ sub Capture
|
1065 | 1070 | glMatrixMode( GL_PROJECTION );
|
1066 | 1071 | glPushMatrix();
|
1067 | 1072 | glLoadIdentity();
|
1068 |
| - eval { gluOrtho2D( 0, $w, 0, $h ); 1 } or $er++ or warn "Catched: $@"; |
| 1073 | + eval { glOrtho( 0, $w, 0, $h, -1, 1 ); 1 } or $er++ or warn "Catched: $@"; |
1069 | 1074 | glMatrixMode( GL_MODELVIEW );
|
1070 | 1075 | glPushMatrix();
|
1071 | 1076 | glLoadIdentity();
|
@@ -1408,16 +1413,6 @@ sub cbMouseClick
|
1408 | 1413 | if ($state == GLUT_UP)
|
1409 | 1414 | {
|
1410 | 1415 | my ($model, $projection, $viewport) = dumpMatrices();
|
1411 |
| - my @point = gluUnProject_p($x,$y,0, # Cursor point |
1412 |
| - @$model, # Model Matrix |
1413 |
| - @$projection, # Projection Matrix |
1414 |
| - @$viewport); # Viewport |
1415 |
| - print "Model point: $point[0], $point[1], $point[2]\n"; |
1416 |
| -# @point = gluProject_p(@point, # Model point |
1417 |
| -# @model, # Model Matrix |
1418 |
| -# @projection, # Projection Matrix |
1419 |
| -# @viewport); # Viewport |
1420 |
| -# print "Window point: $point[0], $point[1], $point[2]\n"; |
1421 | 1416 | print "\n";
|
1422 | 1417 | }
|
1423 | 1418 |
|
@@ -1456,26 +1451,26 @@ sub GetKeyModifier
|
1456 | 1451 | # ------
|
1457 | 1452 | # Callback routine executed whenever our window is resized. Lets us
|
1458 | 1453 | # request the newly appropriate perspective projection matrix for
|
1459 |
| -# our needs. Try removing the gluPerspective() call to see what happens. |
1460 |
| - |
1461 |
| -sub cbResizeScene |
1462 |
| -{ |
| 1454 | +# our needs. Try removing the glFrustum() call to see what happens. |
| 1455 | + |
| 1456 | +use constant PI => 3.1415926535897932384626433832795; |
| 1457 | +use constant FOVY => 45.0; |
| 1458 | +use constant ANGLE => FOVY / 360 * PI; |
| 1459 | +use constant TAN => sin(ANGLE)/cos(ANGLE); |
| 1460 | +use constant { zNEAR => 0.1, zFAR => 100.0 }; |
| 1461 | +use constant fH => TAN * zNEAR; |
| 1462 | +sub cbResizeScene { |
1463 | 1463 | my($Width, $Height) = @_;
|
1464 |
| - |
1465 | 1464 | # Let's not core dump, no matter what.
|
1466 | 1465 | $Height = 1 if ($Height == 0);
|
1467 |
| - |
1468 | 1466 | glViewport(0, 0, $Width, $Height);
|
1469 |
| - |
1470 | 1467 | glMatrixMode(GL_PROJECTION);
|
1471 | 1468 | glLoadIdentity();
|
1472 |
| - gluPerspective(45.0,$Width/$Height,0.1,100.0); |
1473 |
| - |
| 1469 | + my $fW = fH * $Width/$Height; |
| 1470 | + glFrustum(-$fW, $fW, -fH, fH, zNEAR, zFAR); |
1474 | 1471 | glMatrixMode(GL_MODELVIEW);
|
1475 |
| - |
1476 | 1472 | $Window_Width = $Width;
|
1477 | 1473 | $Window_Height = $Height;
|
1478 |
| - |
1479 | 1474 | $idleTime = $hasHires ? gettimeofday() : time();
|
1480 | 1475 | }
|
1481 | 1476 |
|
@@ -1651,7 +1646,7 @@ sub quit {
|
1651 | 1646 | if ($^O ne 'MSWin32') {
|
1652 | 1647 | my $errors = '';
|
1653 | 1648 | while((my $err = glGetError()) != 0) {
|
1654 |
| - $errors .= "glError: " . gluErrorString($err) . "\n"; |
| 1649 | + $errors .= "glError: " . glpErrorString($err) . "\n"; |
1655 | 1650 | }
|
1656 | 1651 | die $errors if $errors;
|
1657 | 1652 | }
|
|
0 commit comments