@@ -152,7 +152,7 @@ fs_out_flat => " $FRAG_OUT = in_diffuse;\n",
152152vs_in => " vec3 the_position = position;\n " ,
153153vs_in_offset_decl => " $VS_IN vec3 offset;\n " ,
154154vs_do_offset => " the_position += offset;\n " ,
155- vs_do_toffset => " gl_Position /= gl_Position.w;\n gl_Position.xy += toffset;\n " ,
155+ vs_do_toffset => " gl_Position /= gl_Position.w;\n gl_Position.xy += toffset * 2.5 / uScreenSize ;\n " ,
156156vs_out => " gl_Position = uMVP * vec4(the_position, 1);\n " ,
157157vs_out_light => <<'EOF' ,
158158 vNormal = normalize(uNormalMatrix * normal);
@@ -206,6 +206,7 @@ uniform mat4 uMV;
206206uniform mat4 uMVP;
207207uniform mat3 uNormalMatrix;
208208EOF
209+ u_screensize_decl => " uniform vec2 uScreenSize;\n " ,
209210);
210211
211212{ package # hide from PAUSE
@@ -225,7 +226,7 @@ use OpenGL::Modern qw(
225226 glCreateProgram glDeleteProgram glLinkProgram glUseProgram glIsProgram
226227 glGetProgramiv_p glGetProgramInfoLog_p
227228 glGetAttribLocation glEnableVertexAttribArray
228- glGetUniformLocation glUniform1i glUniform1f glUniform4f
229+ glGetUniformLocation glUniform1i glUniform1f glUniform2f glUniform4f
229230 glUniformMatrix3fv_p glUniformMatrix4fv_p
230231 glVertexAttribPointer_c
231232 GL_COMPILE_STATUS GL_LINK_STATUS GL_FALSE GL_TRUE
@@ -292,6 +293,7 @@ sub load_attrib {
292293my %SUFFIX2FUNC = (
293294 ' 1i' => \&glUniform1i,
294295 ' 1f' => \&glUniform1f,
296+ ' 2f' => \&glUniform2f,
295297 ' 4f' => \&glUniform4f,
296298 ' Mat3' => \&glUniformMatrix3fv_p,
297299 ' Mat4' => \&glUniformMatrix4fv_p,
@@ -482,10 +484,12 @@ sub _font_setup {
482484 $texcoords -> slice(' (0),0:1' ) .= $leftbound -> dummy(0,1); # u of left
483485 $texcoords -> slice(' (0),2:3' ) .= $rightbound -> dummy(0,1); # u of right
484486 $texcoords -> slice(' (1),0::2' ) .= 1; # v of top, v bot=already 0
487+ $fref -> {vert_template } = PDL-> new(PDL::float, [0,1], [0,0], [1,1], [1,0])
488+ * PDL::float(1, $fref -> {heightpix });
485489}
486490my $vertex_shader = join ' ' , @SHADERBITS {qw( version
487491 vs_in_position_decl vs_in_toffset_decl
488- vs_in_texcoord_decl vs_out_texcoord_decl u_matrix_decl
492+ vs_in_texcoord_decl vs_out_texcoord_decl u_matrix_decl u_screensize_decl
489493 main_start vs_in vs_out vs_do_toffset vs_out_texcoord main_end
490494) };
491495my $fragment_shader = join ' ' , @SHADERBITS {qw( version
@@ -501,10 +505,6 @@ sub togl_setup {
501505 });
502506 $points //= $this -> {Points }; # as Labels is used in Graph
503507 my $numchars = $FONT {numchars };
504- my $vert_template = PDL-> new(PDL::float, [0,1], [0,0], [1,1], [1,0]);
505- my $dwidth = $PDL::Graphics::TriD::Window::DEFAULT_WIDTH / 2.5;
506- my $dheight = $PDL::Graphics::TriD::Window::DEFAULT_HEIGHT / 2.5;
507- $vert_template *= PDL::float(1 / $dwidth , $FONT {heightpix } / $dheight );
508508 my @codes = map [map ord , split //], @{ $this -> {Strings } };
509509 my ($v2 , @v1 , @v3 ) = PDL-> null;
510510 for (0..$#codes ) {
@@ -516,8 +516,8 @@ sub togl_setup {
516516 }
517517 my $v = $points -> dice_axis(1, \@v1 )-> dummy(1,4);
518518 my $toffset =
519- ( $v2 -> t-> append([0])-> dummy(1) / $dwidth ) +
520- $vert_template * $FONT {widthflt1 }-> dice_axis(2,\@v3 );
519+ $v2 -> t-> append([0])-> dummy(1) +
520+ $FONT { vert_template } * $FONT {widthflt1 }-> dice_axis(2,\@v3 );
521521 $this -> {Impl }{program_nodestroy } = $this -> cache_do(prog => ' shader' , sub {
522522 $this -> compile_program($vertex_shader , $fragment_shader );
523523 });
@@ -922,6 +922,7 @@ sub display {
922922 my $fW = fH * $vp -> {W }/$vp -> {H }; # aspect ratio
923923 my $p = $this -> frustum(-$fW , $fW , -fH, fH, zNEAR, zFAR);
924924 $vp -> togl({
925+ uScreenSize => [ ' 2f' => [@$vp {qw( W H) }] ],
925926 uMV => [ Mat4 => [1, 1, $mv -> list] ], # count, xpose, ...
926927 uMVP => [ Mat4 => [1, 1, ($p x $mv )-> list] ], # count, xpose, ...
927928 uNormalMatrix => [ Mat3 => [1, 1, $mv -> slice(' 0:2,0:2' )-> inv-> t-> list] ],
0 commit comments