Forums > Jitter

rendering 2d text

March 13, 2007 | 9:23 pm

hey,
so what’s the best way to render 2d text to screen in ortho mode (so
that it ignores all transformations)?
i tried rendering the text using jit.text2d and rendering it using
jit.gl.sketch. but when i set ignore attributes on, i get stack
overflow errors.
here’s a demo patch.
thanks in advance,
jeremy

max v2;
#N vpatcher 64 51 1093 750;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 87 308 100 196617 sprintf text %ld fps;
#P newex 87 284 51 196617 route fps;
#P newex 34 225 53 196617 t getfps b;
#P window linecount 4;
#P message 525 465 313 196617 reset , gldisable depth_test ,
glmatrixmode projection , glloadidentity , glortho 0. 800. 600. 0.
-5. 5. , gltranslate 100 100 , glmatrixmode modelview ,
glloadidentity , glpushmatrix , glcolor 1. 1. 1. 1. , drawobject
mytext 1 , glpopmatrix , glenable depth_test;
#P window linecount 1;
#P newex 525 527 101 196617 jit.gl.sketch context;
#P message 111 334 50 196617 text test;
#P window linecount 2;
#P newex 87 375 253 196617 jit.gl.text2d context @color 1. 1. 1. 1.
@depth_enable 1 @name mytext @automatic 0 @align 1;
#P toggle 228 595 15 0;
#P user jit.fpsgui 34 251 63 196617 0;
#P flonum 150 484 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 34 507 129 196617 pak erase_color 0. 0. 0. 0.;
#P newex 33 645 220 196617 jit.window context @floating 1
@depthbuffer 1;
#P newex 121 164 59 196617 s to_movie;
#P newex 179 107 62 196617 s to_render;
#P newex 92 198 62 196617 s to_render;
#P newex 150 134 55 196617 s to_shape;
#P number 79 35 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 58 552 33 196617 reset;
#P newex 47 530 62 196617 r to_render;
#P newex 58 573 274 196617 jit.gl.handle context @auto_rotate 1
@inherit_transform 1;
#P newex 34 77 156 196617 t b b b b b erase;
#P toggle 34 34 15 0;
#P newex 34 54 55 196617 qmetro 50;
#P newex 34 617 101 196617 jit.gl.render context;
#P connect 2 0 1 0;
#P connect 1 0 3 0;
#P connect 3 0 21 0;
#P connect 21 0 15 0;
#P connect 21 1 15 0;
#P connect 13 0 0 0;
#P fasten 5 0 0 0 52 610 39 610;
#P fasten 4 0 0 0 63 610 39 610;
#P connect 6 0 4 0;
#P connect 7 0 1 1;
#P connect 15 1 22 0;
#P connect 22 0 23 0;
#P connect 18 0 17 0;
#P connect 23 0 17 0;
#P connect 3 2 9 0;
#P connect 3 3 11 0;
#P connect 3 4 8 0;
#P connect 14 0 13 4;
#P connect 3 5 10 0;
#P connect 20 0 19 0;
#P pop;


March 16, 2007 | 9:24 pm

i never did figure this out. but it looks to me like it’s an internal
problem with jit.gl.text2d (osx 10.4.8, max 4.62, jitter 1.62).

here’s the error max generates.

jit.gl.text2d:draw_layouts:glPopMatrix: GL Error: Stack overflow
ob3d_draw_end popmatrix: GL Error: Stack underflow

just in case somebody else needs a workaround, i made an abstraction
using jit.lcd, jit.matrix and jit.gl.sketch.

jeremy

max v2;
#N vpatcher 64 51 1126 786;
#P window setfont "Sans Serif" 9.;
#P newex 216 612 313 196617 jit.gl.gridshape context @shape cube
@lighting_enable 1 @scale 0.3;
#P user jit.pwindow 282 470 82 62 0 1 0 0 1 0;
#P newex 633 501 40 196617 t b b b;
#P newex 87 458 143 196617 jit.matrix @planemap 1 0 0 0;
#P window linecount 5;
#P message 633 628 376 196617 glpushmatrix , gltranslate 30 100 0 ,
glcolor 1. 1. 1. 1. , glenable texture_2d , glbindtexture info ,
glenable blend , glblendfunc 6 7 , glscale 256 75 , glcolor 1. 1.
1. 1. , glbegin quads , gltexcoord 0. 0.5555 , glvertex 0. 0. ,
gltexcoord 1. 0.5555 , glvertex 1. 0. , gltexcoord 1. 0.8888 ,
glvertex 1. 1. , gltexcoord 0. 0.8888 , glvertex 0. 1. , glend ,
gldisable texture_2d , gldisable blend , glpopmatrix;
#P message 648 557 364 196617 glpushmatrix , gltranslate 30 10 0 ,
glcolor 1. 1. 1. 1. , glenable texture_2d , glbindtexture info ,
glenable blend , glblendfunc 6 7 , glscale 256 75 , glcolor 1. 1.
1. 1. , glbegin quads , gltexcoord 0. 0. , glvertex 0. 0. ,
gltexcoord 1. 0. , glvertex 1. 0. , gltexcoord 1. 0.3333 ,
glvertex 1. 1. , gltexcoord 0. 0.3333 , glvertex 0. 1. , glend ,
gldisable texture_2d , gldisable blend , glpopmatrix;
#P window linecount 2;
#P message 663 524 331 196617 reset , gldisable depth_test ,
glmatrixmode projection , glloadidentity , glortho 0. 512. 512. 0.
-5. 5. , glmatrixmode modelview , glloadidentity;
#P window linecount 1;
#P newex 543 229 53 196617 t b b b b;
#P newex 579 199 48 196617 loadbang;
#P newex 219 250 27 196617 int;
#P message 469 326 137 196617 write Load QuickTime movie;
#P window linecount 2;
#P newex 469 464 363 196617 jit.matrix infomtx 4 char 256 256
@usesrcdim 1 @usedstdim 1 @srcdimstart 0 0 @srcdimend 255 127
@dstdimstart 0 128 @dstdimend 255 255;
#P window linecount 1;
#P message 503 388 73 196617 moveto 20 40;
#P message 513 413 296 196617 reset , brgb 0 0 0 , frgb 255 255 255
, moveto 50 50 , font 0 20;
#P newex 469 357 62 196617 t b l b clear;
#P newex 469 440 111 196617 jit.lcd 4 char 256 256;
#P newex 87 501 63 196617 s to_render;
#P newex 87 478 102 196617 prepend texture info;
#P window linecount 2;
#P newex 88 425 363 196617 jit.matrix infomtx 4 char 256 256
@usesrcdim 1 @usedstdim 1 @srcdimstart 0 0 @srcdimend 255 149
@dstdimstart 0 0 @dstdimend 255 149;
#P number 271 336 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 271 353 58 196617 font $1 20;
#P message 121 363 73 196617 moveto 20 35;
#P message 131 388 296 196617 reset , brgb 0 0 0 , frgb 255 255 255
, moveto 50 50 , font 0 20;
#P user jit.pwindow 687 84 258 258 0 1 0 0 1 0;
#P newex 87 332 62 196617 t b l b clear;
#P newex 87 403 111 196617 jit.lcd 4 char 256 256;
#P newex 87 308 106 196617 sprintf write %ld fps;
#P newex 87 284 51 196617 route fps;
#P newex 34 225 53 196617 t getfps b;
#P newex 477 632 101 196617 jit.gl.sketch context;
#P user jit.fpsgui 34 251 63 196617 0;
#P flonum 189 519 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 35 520 129 196617 pak erase_color 0. 0. 0. 0.;
#P window linecount 2;
#P newex 34 656 221 196617 jit.window context @floating 1
@depthbuffer 1 @size 512 512;
#P window linecount 1;
#P newex 121 164 59 196617 s to_movie;
#P newex 179 107 62 196617 s to_render;
#P newex 92 198 62 196617 s to_render;
#P newex 150 134 55 196617 s to_shape;
#P number 79 35 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 59 565 33 196617 reset;
#P newex 48 543 62 196617 r to_render;
#P newex 59 586 274 196617 jit.gl.handle context @auto_rotate 1
@inherit_transform 1;
#P newex 34 77 156 196617 t b b b b b erase;
#P toggle 34 34 15 0;
#P newex 34 54 55 196617 qmetro 50;
#P newex 35 630 101 196617 jit.gl.render context;
#P connect 2 0 1 0;
#P connect 1 0 3 0;
#P connect 3 0 17 0;
#P connect 17 0 15 0;
#P connect 17 1 15 0;
#P connect 13 0 0 0;
#P fasten 5 0 0 0 53 623 40 623;
#P fasten 4 0 0 0 64 623 40 623;
#P connect 6 0 4 0;
#P connect 7 0 1 1;
#P connect 15 1 18 0;
#P connect 36 0 19 0;
#P connect 19 0 21 0;
#P connect 23 0 20 0;
#P connect 21 0 20 0;
#P connect 21 1 20 0;
#P connect 21 3 20 0;
#P connect 24 0 20 0;
#P connect 25 0 20 0;
#P connect 27 0 42 0;
#P connect 42 0 28 0;
#P connect 28 0 29 0;
#P connect 20 0 27 0;
#P connect 3 2 9 0;
#P connect 3 3 11 0;
#P connect 21 2 24 0;
#P connect 38 2 23 0;
#P connect 3 4 8 0;
#P connect 14 0 13 4;
#P connect 3 5 10 0;
#P connect 18 0 36 0;
#P connect 26 0 25 0;
#P connect 38 1 35 0;
#P connect 35 0 31 0;
#P connect 33 0 30 0;
#P connect 31 3 30 0;
#P connect 31 1 30 0;
#P connect 31 0 30 0;
#P connect 32 0 30 0;
#P connect 30 0 34 0;
#P connect 39 0 16 0;
#P connect 40 0 16 0;
#P connect 41 0 16 0;
#P connect 31 2 33 0;
#P connect 38 3 32 0;
#P connect 37 0 38 0;
#P connect 38 0 43 0;
#P connect 43 0 41 0;
#P connect 43 1 40 0;
#P connect 43 2 39 0;
#P connect 34 0 22 0;
#P pop;

On Mar 13, 2007, at 5:23 PM, Jeremy Rotsztain wrote:

>
> hey,
> so what’s the best way to render 2d text to screen in ortho mode
> (so that it ignores all transformations)?
> i tried rendering the text using jit.text2d and rendering it using
> jit.gl.sketch. but when i set ignore attributes on, i get stack
> overflow errors.
> here’s a demo patch.
> thanks in advance,
> jeremy
>
> max v2;
> #N vpatcher 64 51 1093 750;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 87 308 100 196617 sprintf text %ld fps;
> #P newex 87 284 51 196617 route fps;
> #P newex 34 225 53 196617 t getfps b;
> #P window linecount 4;
> #P message 525 465 313 196617 reset , gldisable depth_test ,
> glmatrixmode projection , glloadidentity , glortho 0. 800. 600.
> 0. -5. 5. , gltranslate 100 100 , glmatrixmode modelview ,
> glloadidentity , glpushmatrix , glcolor 1. 1. 1. 1. , drawobject
> mytext 1 , glpopmatrix , glenable depth_test;
> #P window linecount 1;
> #P newex 525 527 101 196617 jit.gl.sketch context;
> #P message 111 334 50 196617 text test;
> #P window linecount 2;
> #P newex 87 375 253 196617 jit.gl.text2d context @color 1. 1. 1. 1.
> @depth_enable 1 @name mytext @automatic 0 @align 1;
> #P toggle 228 595 15 0;
> #P user jit.fpsgui 34 251 63 196617 0;
> #P flonum 150 484 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P newex 34 507 129 196617 pak erase_color 0. 0. 0. 0.;
> #P newex 33 645 220 196617 jit.window context @floating 1
> @depthbuffer 1;
> #P newex 121 164 59 196617 s to_movie;
> #P newex 179 107 62 196617 s to_render;
> #P newex 92 198 62 196617 s to_render;
> #P newex 150 134 55 196617 s to_shape;
> #P number 79 35 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 58 552 33 196617 reset;
> #P newex 47 530 62 196617 r to_render;
> #P newex 58 573 274 196617 jit.gl.handle context @auto_rotate 1
> @inherit_transform 1;
> #P newex 34 77 156 196617 t b b b b b erase;
> #P toggle 34 34 15 0;
> #P newex 34 54 55 196617 qmetro 50;
> #P newex 34 617 101 196617 jit.gl.render context;
> #P connect 2 0 1 0;
> #P connect 1 0 3 0;
> #P connect 3 0 21 0;
> #P connect 21 0 15 0;
> #P connect 21 1 15 0;
> #P connect 13 0 0 0;
> #P fasten 5 0 0 0 52 610 39 610;
> #P fasten 4 0 0 0 63 610 39 610;
> #P connect 6 0 4 0;
> #P connect 7 0 1 1;
> #P connect 15 1 22 0;
> #P connect 22 0 23 0;
> #P connect 18 0 17 0;
> #P connect 23 0 17 0;
> #P connect 3 2 9 0;
> #P connect 3 3 11 0;
> #P connect 3 4 8 0;
> #P connect 14 0 13 4;
> #P connect 3 5 10 0;
> #P connect 20 0 19 0;
> #P pop;
>


Viewing 2 posts - 1 through 2 (of 2 total)