Skip to content

Commit 28752ea

Browse files
committed
replace gl_triangles*_mat with glColorMaterial
1 parent 4f15ee8 commit 28752ea

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

lib/PDL/Graphics/OpenGLQ.pd

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ sub COLOR { make_tri("glColor3f",'$colors',@_) }
7474
sub VERTEX { make_tri("glVertex3f",'$coords',@_) }
7575
sub NORMAL { make_tri("glNormal3f",'$norm',@_) }
7676
sub RPOS { make_tri("glRasterPos3f",'$coords',@_) }
77-
sub ADCOLOR { "
78-
{
79-
GLfloat ad[] = { ".TRI('$colors'.$_[0]).",1.0 };
80-
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE, ad);
81-
}
82-
" }
8377

8478
sub make_func {
8579
my ($name) = @_;
@@ -121,12 +115,6 @@ pp_def(
121115
@internal
122116
);
123117

124-
for my $m (
125-
{Suf => '_mat',
126-
Func => \&ADCOLOR},
127-
{Suf => '',
128-
Func => \&COLOR},
129-
) {
130118
for(
131119
{Name => 'gl_triangles'},
132120
{Name => 'gl_triangles_n',
@@ -155,7 +143,7 @@ for(
155143
# This may be suboptimal but should still be fast enough..
156144
# We only do triangles with this.
157145
pp_def(
158-
$_->{Name}.$m->{Suf},
146+
$_->{Name},
159147
GenericTypes => $F,
160148
Pars => 'coordsa(tri=3); coordsb(tri); coordsc(tri);'.
161149
($_->{NormalArgs}//'').
@@ -166,18 +154,17 @@ pp_def(
166154
broadcastloop %{'.
167155
($_->{NormalInit}//"\n").
168156
($_->{NormalCodeA}//'').
169-
$m->{Func}->("a").VERTEX("a").
157+
COLOR("a").VERTEX("a").
170158
($_->{NormalCodeB}//'').
171-
$m->{Func}->("b").VERTEX("b").
159+
COLOR("b").VERTEX("b").
172160
($_->{NormalCodeC}//'').
173-
$m->{Func}->("c").VERTEX("c").'
161+
COLOR("c").VERTEX("c").'
174162
%}
175163
glEnd();
176164
',
177165
@internal
178166
);
179167
}
180-
}
181168

182169
pp_def('gl_arrows',
183170
Pars => 'coords(tri=3,n); indx indsa(); indx indsb();',

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ sub PDL::Graphics::TriD::Lattice::gdraw {
198198
} else {
199199
glShadeModel($shading == 1 ? GL_FLAT : GL_SMOOTH);
200200
my $f = 'PDL::gl_triangles';
201-
$f .= '_' . ($this->{Options}{Smooth} ? 'w' : '') . 'n_mat' if $shading > 2;
201+
$f .= '_' . ($this->{Options}{Smooth} ? 'w' : '') . 'n' if $shading > 2;
202202
{ no strict 'refs'; $f = \&$f; }
203+
if ($shading > 2) { glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); }
203204
_lattice_slice($f, $points, $this->{Options}{Smooth} ? $this->{VertexNormals} : (), $this->{Colors});
205+
if ($shading > 2) { glDisable(GL_COLOR_MATERIAL); }
204206
$this->_lattice_lines($points) if $this->{Options}{Lines};
205207
}
206208
if ($this->{Options}{ShowNormals}) {
@@ -252,12 +254,14 @@ sub PDL::Graphics::TriD::Trigrid::gdraw {
252254
glShadeModel(GL_SMOOTH); # By-vertex doesn't make sense otherwise.
253255
my $f = 'PDL::gl_triangles';
254256
my $send_normals = $this->{Options}{Smooth} && $this->{Options}{Shading};
255-
$f .= '_' . ($send_normals ? 'w' : '') . 'n_mat' if $this->{Options}{Shading};
257+
$f .= '_' . ($send_normals ? 'w' : '') . 'n' if $this->{Options}{Shading};
256258
{ no strict 'refs'; $f = \&$f; }
257259
my $tmpn = $send_normals
258260
? $this->{VertexNormals}->dice_axis(1,$this->{Faceidx}->flat)
259261
->splitdim(1,$this->{Faceidx}->dim(0)) : undef;
262+
if ($this->{Options}{Shading}) { glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); }
260263
$f->(map $_->mv(1,-1)->dog, $faces, $send_normals ? $tmpn : (), $colours);
264+
if ($this->{Options}{Shading}) { glDisable(GL_COLOR_MATERIAL); }
261265
if ($this->{Options}{ShowNormals}) {
262266
die "No normals to show!" if !grep defined $this->{$_}, qw(FaceNormals VertexNormals);
263267
if (defined $this->{VertexNormals}) {

0 commit comments

Comments
 (0)