|
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!
|
@@ -588,12 +584,16 @@ sub ourBuildTextures
|
588 | 584 | GL_NEAREST);
|
589 | 585 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
590 | 586 | 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); |
| 587 | + glTexImage2D_c(GL_TEXTURE_2D, 0, $Tex_Type, |
| 588 | + $Tex_Width, $Tex_Height, |
| 589 | + 0, $Tex_Format, $Tex_Size, $Tex_Pixels->ptr); |
| 590 | + glGenerateMipmapEXT(GL_TEXTURE_2D); |
| 591 | + if ($^O ne 'MSWin32') { |
| 592 | + my $errors = ''; |
| 593 | + while((my $err = glGetError()) != 0) { |
| 594 | + $errors .= "glError: " . glpErrorString($err) . "\n"; |
| 595 | + } |
| 596 | + die $errors if $errors; |
597 | 597 | }
|
598 | 598 |
|
599 | 599 | # Benchmarks for Image Loading
|
@@ -679,7 +679,7 @@ sub ourBuildTextures
|
679 | 679 |
|
680 | 680 | # Test status
|
681 | 681 | my $stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
682 |
| - die "FBO Status error: " . gluErrorString(glGetError()) if !$stat; |
| 682 | + die "FBO Status error: " . glpGetError(glGetError()) if !$stat; |
683 | 683 | die sprintf "FBO Status: %04X", $stat if $stat != GL_FRAMEBUFFER_COMPLETE_EXT;
|
684 | 684 | }
|
685 | 685 |
|
@@ -1065,7 +1065,7 @@ sub Capture
|
1065 | 1065 | glMatrixMode( GL_PROJECTION );
|
1066 | 1066 | glPushMatrix();
|
1067 | 1067 | glLoadIdentity();
|
1068 |
| - eval { gluOrtho2D( 0, $w, 0, $h ); 1 } or $er++ or warn "Catched: $@"; |
| 1068 | + eval { glOrtho( 0, $w, 0, $h, -1, 1 ); 1 } or $er++ or warn "Catched: $@"; |
1069 | 1069 | glMatrixMode( GL_MODELVIEW );
|
1070 | 1070 | glPushMatrix();
|
1071 | 1071 | glLoadIdentity();
|
@@ -1408,16 +1408,6 @@ sub cbMouseClick
|
1408 | 1408 | if ($state == GLUT_UP)
|
1409 | 1409 | {
|
1410 | 1410 | 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 | 1411 | print "\n";
|
1422 | 1412 | }
|
1423 | 1413 |
|
@@ -1456,26 +1446,26 @@ sub GetKeyModifier
|
1456 | 1446 | # ------
|
1457 | 1447 | # Callback routine executed whenever our window is resized. Lets us
|
1458 | 1448 | # 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 |
| -{ |
| 1449 | +# our needs. Try removing the glFrustum() call to see what happens. |
| 1450 | + |
| 1451 | +use constant PI => 3.1415926535897932384626433832795; |
| 1452 | +use constant FOVY => 45.0; |
| 1453 | +use constant ANGLE => FOVY / 360 * PI; |
| 1454 | +use constant TAN => sin(ANGLE)/cos(ANGLE); |
| 1455 | +use constant { zNEAR => 0.1, zFAR => 100.0 }; |
| 1456 | +use constant fH => TAN * zNEAR; |
| 1457 | +sub cbResizeScene { |
1463 | 1458 | my($Width, $Height) = @_;
|
1464 |
| - |
1465 | 1459 | # Let's not core dump, no matter what.
|
1466 | 1460 | $Height = 1 if ($Height == 0);
|
1467 |
| - |
1468 | 1461 | glViewport(0, 0, $Width, $Height);
|
1469 |
| - |
1470 | 1462 | glMatrixMode(GL_PROJECTION);
|
1471 | 1463 | glLoadIdentity();
|
1472 |
| - gluPerspective(45.0,$Width/$Height,0.1,100.0); |
1473 |
| - |
| 1464 | + my $fW = fH * $Width/$Height; |
| 1465 | + glFrustum(-$fW, $fW, -fH, fH, zNEAR, zFAR); |
1474 | 1466 | glMatrixMode(GL_MODELVIEW);
|
1475 |
| - |
1476 | 1467 | $Window_Width = $Width;
|
1477 | 1468 | $Window_Height = $Height;
|
1478 |
| - |
1479 | 1469 | $idleTime = $hasHires ? gettimeofday() : time();
|
1480 | 1470 | }
|
1481 | 1471 |
|
@@ -1651,7 +1641,7 @@ sub quit {
|
1651 | 1641 | if ($^O ne 'MSWin32') {
|
1652 | 1642 | my $errors = '';
|
1653 | 1643 | while((my $err = glGetError()) != 0) {
|
1654 |
| - $errors .= "glError: " . gluErrorString($err) . "\n"; |
| 1644 | + $errors .= "glError: " . glpErrorString($err) . "\n"; |
1655 | 1645 | }
|
1656 | 1646 | die $errors if $errors;
|
1657 | 1647 | }
|
|
0 commit comments