Skip to content

Commit 841e975

Browse files
committed
test.pl stop using GLU
1 parent a2b8b4d commit 841e975

File tree

6 files changed

+82
-42
lines changed

6 files changed

+82
-42
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

+37-42
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!
@@ -582,18 +578,27 @@ sub ourBuildTextures
582578
}
583579
glBindTexture(GL_TEXTURE_2D, $TextureID_image);
584580

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;
597602
}
598603

599604
# Benchmarks for Image Loading
@@ -679,7 +684,7 @@ sub ourBuildTextures
679684

680685
# Test status
681686
my $stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
682-
die "FBO Status error: " . gluErrorString(glGetError()) if !$stat;
687+
die "FBO Status error: " . glpErrorString(glGetError()) if !$stat;
683688
die sprintf "FBO Status: %04X", $stat if $stat != GL_FRAMEBUFFER_COMPLETE_EXT;
684689
}
685690

@@ -1065,7 +1070,7 @@ sub Capture
10651070
glMatrixMode( GL_PROJECTION );
10661071
glPushMatrix();
10671072
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: $@";
10691074
glMatrixMode( GL_MODELVIEW );
10701075
glPushMatrix();
10711076
glLoadIdentity();
@@ -1408,16 +1413,6 @@ sub cbMouseClick
14081413
if ($state == GLUT_UP)
14091414
{
14101415
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";
14211416
print "\n";
14221417
}
14231418

@@ -1456,26 +1451,26 @@ sub GetKeyModifier
14561451
# ------
14571452
# Callback routine executed whenever our window is resized. Lets us
14581453
# 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 {
14631463
my($Width, $Height) = @_;
1464-
14651464
# Let's not core dump, no matter what.
14661465
$Height = 1 if ($Height == 0);
1467-
14681466
glViewport(0, 0, $Width, $Height);
1469-
14701467
glMatrixMode(GL_PROJECTION);
14711468
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);
14741471
glMatrixMode(GL_MODELVIEW);
1475-
14761472
$Window_Width = $Width;
14771473
$Window_Height = $Height;
1478-
14791474
$idleTime = $hasHires ? gettimeofday() : time();
14801475
}
14811476

@@ -1651,7 +1646,7 @@ sub quit {
16511646
if ($^O ne 'MSWin32') {
16521647
my $errors = '';
16531648
while((my $err = glGetError()) != 0) {
1654-
$errors .= "glError: " . gluErrorString($err) . "\n";
1649+
$errors .= "glError: " . glpErrorString($err) . "\n";
16551650
}
16561651
die $errors if $errors;
16571652
}

0 commit comments

Comments
 (0)