Skip to content

Commit 6016b21

Browse files
committed
test.pl stop using GLU
1 parent a2b8b4d commit 6016b21

File tree

6 files changed

+71
-36
lines changed

6 files changed

+71
-36
lines changed

Changes

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- add glpErrorString
2+
13
0.7006 2025-04-14
24
- incorporate Acme::MITHALDU::BleedingOpenGL changes - thanks @wchristian
35
- add glGenVertexArrays_p, glBindVertexArray, glDeleteVertexArrays

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ FreeGLUT/freeglut.lib
3737
FreeGLUT/README.txt
3838
genvars.pl
3939
gl_const.h
40+
gl_errors.h
4041
gl_util.c
4142
gl_util.h
4243
glext_consts.h

gl_errors.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
#define GL_NO_ERROR 0
3+
#define GL_INVALID_ENUM 0x0500
4+
#define GL_INVALID_VALUE 0x0501
5+
#define GL_INVALID_OPERATION 0x0502
6+
#define GL_STACK_OVERFLOW 0x0503
7+
#define GL_STACK_UNDERFLOW 0x0504
8+
#define GL_OUT_OF_MEMORY 0x0505
9+
#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
10+
#define GL_CONTEXT_LOST 0x0507
11+
*/
12+
13+
const char* const gl_error_symbol_strings[] = {
14+
"GL_NO_ERROR",
15+
"GL_INVALID_ENUM",
16+
"GL_INVALID_VALUE",
17+
"GL_INVALID_OPERATION",
18+
"GL_STACK_OVERFLOW",
19+
"GL_STACK_UNDERFLOW",
20+
"GL_OUT_OF_MEMORY",
21+
"GL_INVALID_FRAMEBUFFER_OPERATION",
22+
"GL_CONTEXT_LOST",
23+
};
24+
25+
int is_gl_error(int rval) {
26+
if (!(rval & 0x0507)) return 0;
27+
return (rval & 0x07) + 1;
28+
}
29+
30+
const char* gl_error_string(int err) {
31+
return gl_error_symbol_strings[is_gl_error(err)];
32+
}

lib/OpenGL.pm

+1
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ our @gl_func = (@gl_func_common, qw(
12091209
glWindowPos4dMESA
12101210
glWindowPos4iMESA
12111211
glpCheckExtension
1212+
glpErrorString
12121213
glpFullScreen
12131214
glpHasGLUT
12141215
glpRestoreScreen

lib/OpenGL/V1.xs

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdio.h>
99

1010
#include "pgopogl.h"
11+
#include "gl_errors.h"
1112

1213
#ifdef HAVE_GL
1314
#include "gl_util.h"
@@ -10322,4 +10323,12 @@ glBlendColorEXT(red, green, blue, alpha)
1032210323

1032310324
#endif
1032410325

10326+
const char *
10327+
glpErrorString(err)
10328+
int err
10329+
CODE:
10330+
RETVAL = gl_error_string(err);
10331+
OUTPUT:
10332+
RETVAL
10333+
1032510334
#endif /* HAVE_GL */

test.pl

+26-36
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use OpenGL qw/
88
:glconstants
99
glpHasGLUT glpCheckExtension glpFullScreen glpRestoreScreen
10-
glGetString glGetError
10+
glGetString glGetError glpErrorString
1111
glGenTextures_p glBindTexture glTexParameteri glTexImage2D_c glTexEnvf
1212
glDeleteTextures_p
1313
glGenerateMipmapEXT
@@ -25,7 +25,7 @@
2525
glTranslatef glRotatef
2626
glColor3f glColor4f
2727
glPushMatrix glPopMatrix glPushAttrib glPopAttrib
28-
glOrtho
28+
glOrtho glFrustum
2929
glRasterPos2i glRasterPos2f
3030
glPixelZoom glReadPixels_c glDrawPixels_c
3131
glGetDoublev_c glGetIntegerv_c
@@ -34,10 +34,6 @@
3434
use OpenGL::GLUT qw/
3535
:constants :functions
3636
/;
37-
use OpenGL::GLU qw/
38-
gluBuild2DMipmaps_c gluErrorString
39-
gluOrtho2D gluProject_p gluUnProject_p gluPerspective
40-
/;
4137
use OpenGL::Config; # for build information
4238

4339
eval 'use OpenGL::Image 1.03'; # Need to use OpenGL::Image 1.03 or higher!
@@ -588,12 +584,16 @@ sub ourBuildTextures
588584
GL_NEAREST);
589585
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
590586
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;
597597
}
598598

599599
# Benchmarks for Image Loading
@@ -679,7 +679,7 @@ sub ourBuildTextures
679679

680680
# Test status
681681
my $stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
682-
die "FBO Status error: " . gluErrorString(glGetError()) if !$stat;
682+
die "FBO Status error: " . glpGetError(glGetError()) if !$stat;
683683
die sprintf "FBO Status: %04X", $stat if $stat != GL_FRAMEBUFFER_COMPLETE_EXT;
684684
}
685685

@@ -1065,7 +1065,7 @@ sub Capture
10651065
glMatrixMode( GL_PROJECTION );
10661066
glPushMatrix();
10671067
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: $@";
10691069
glMatrixMode( GL_MODELVIEW );
10701070
glPushMatrix();
10711071
glLoadIdentity();
@@ -1408,16 +1408,6 @@ sub cbMouseClick
14081408
if ($state == GLUT_UP)
14091409
{
14101410
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";
14211411
print "\n";
14221412
}
14231413

@@ -1456,26 +1446,26 @@ sub GetKeyModifier
14561446
# ------
14571447
# Callback routine executed whenever our window is resized. Lets us
14581448
# 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 {
14631458
my($Width, $Height) = @_;
1464-
14651459
# Let's not core dump, no matter what.
14661460
$Height = 1 if ($Height == 0);
1467-
14681461
glViewport(0, 0, $Width, $Height);
1469-
14701462
glMatrixMode(GL_PROJECTION);
14711463
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);
14741466
glMatrixMode(GL_MODELVIEW);
1475-
14761467
$Window_Width = $Width;
14771468
$Window_Height = $Height;
1478-
14791469
$idleTime = $hasHires ? gettimeofday() : time();
14801470
}
14811471

@@ -1651,7 +1641,7 @@ sub quit {
16511641
if ($^O ne 'MSWin32') {
16521642
my $errors = '';
16531643
while((my $err = glGetError()) != 0) {
1654-
$errors .= "glError: " . gluErrorString($err) . "\n";
1644+
$errors .= "glError: " . glpErrorString($err) . "\n";
16551645
}
16561646
die $errors if $errors;
16571647
}

0 commit comments

Comments
 (0)