Skip to content

Commit ca3d977

Browse files
committed
gl_triangles take colours as single param
1 parent 552d9ee commit ca3d977

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/PDL/Graphics/OpenGLQ.pd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ pp_def(
6868
@internal
6969
);
7070

71-
sub TRI { my $par = join '', @_; join ',', map "$par(tri => $_)", 0..2 }
71+
sub TRI {
72+
my ($par, $suffix) = @_;
73+
$par .= $suffix if $suffix && !ref $suffix;
74+
my $extra_arg = ref $suffix ? "trivert => $$suffix," : '';
75+
join ',', map "$par(${extra_arg}tri => $_)", 0..2;
76+
}
7277
sub make_tri { shift()."(".TRI(@_).");\n" }
7378
sub COLOR { make_tri("glColor3f",'$colors',@_) }
7479
sub VERTEX { make_tri("glVertex3f",'$coords',@_) }
@@ -128,17 +133,17 @@ pp_def(
128133
GenericTypes => $F,
129134
Pars => 'coordsa(tri=3); coordsb(tri); coordsc(tri);'.
130135
($_->{NormalArgs}//'').
131-
'colorsa(tri); colorsb(tri); colorsc(tri);',
136+
'colors(tri,trivert=3)',
132137
Code => '
133138
glBegin(GL_TRIANGLES);
134139
broadcastloop %{'.
135140
($_->{NormalInit}//"\n").
136141
($_->{NormalCodeA}//'').
137-
COLOR("a").VERTEX("a").
142+
COLOR(\0).VERTEX("a").
138143
($_->{NormalCodeB}//'').
139-
COLOR("b").VERTEX("b").
144+
COLOR(\1).VERTEX("b").
140145
($_->{NormalCodeC}//'').
141-
COLOR("c").VERTEX("c").'
146+
COLOR(\2).VERTEX("c").'
142147
%}
143148
glEnd();',
144149
@internal

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ sub PDL::Graphics::TriD::Lattice::gdraw {
207207
my $tmpn = $shading <= 2 ? undef : $options->{Smooth}
208208
? $this->{VertexNormals}->dice_axis(1,$this->{Faceidx}->flat)
209209
->splitdim(1,$this->{Faceidx}->dim(0)) : $this->{FaceNormals}->dummy(1,3);
210-
$f->(map $_->mv(1,-1)->dog, $faces, $shading > 2 ? $tmpn : (), $colours);
210+
$f->((map $_->mv(1,-1)->dog, $faces, $shading > 2 ? $tmpn : ()), $colours);
211211
if ($shading > 2) { glDisable(GL_COLOR_MATERIAL); }
212212
$this->_lattice_lines($points) if $options->{Lines};
213213
}
@@ -276,7 +276,7 @@ sub PDL::Graphics::TriD::Trigrid::gdraw {
276276
? $this->{VertexNormals}->dice_axis(1,$this->{Faceidx}->flat)
277277
->splitdim(1,$this->{Faceidx}->dim(0)) : $this->{FaceNormals}->dummy(1,3);
278278
if ($options->{Shading}) { glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); }
279-
$f->(map $_->mv(1,-1)->dog, $faces, $options->{Shading} ? $tmpn : (), $colours);
279+
$f->((map $_->mv(1,-1)->dog, $faces, $options->{Shading} ? $tmpn : ()), $colours);
280280
if ($options->{Shading}) { glDisable(GL_COLOR_MATERIAL); }
281281
if ($options->{ShowNormals}) {
282282
die "No normals to show!" if !grep defined $this->{$_}, qw(FaceNormals VertexNormals);

0 commit comments

Comments
 (0)