Creating jitter objects in an external
Hi, pretty new to Jitter and trying to figure some stuff out.
Can I create and access objects in a C external? e.g. in my code, create a jit.text2d for instance, create a temporary matrix and render the text2d into the matrix internally or is that stuff I would have to do int Max?
thx for any pointer
Lee
So, I can create a movie object:
void *movie = jit_object_new( gensym( "jit_qt_movie" ) );
but not a text object:
void *text_2d = jit_object_new( gensym( "jit_gl_text2d" ) );
anyone got any pointers? thx
So, I've got this now, but nothing is rendered to the matrix - is there anything obvious wrong? thx
if ( !( m_p_matrix = jit_object_new(_jit_sym_jit_matrix, &info) ) )
m_p_output->err( "Cannot create matrix" );
else {
jit_object_register( m_p_matrix, gensym( "test_matrix" ) );
// jit_attr_setsym( m_p_matrix,_jit_sym_matrixname, gensym( "test_matrix" ));
if ( !( m_p_text = jit_object_new( gensym( "jit_gl_text" ) ) ) )
m_p_output->err( "Cannot create text" );
else {
jit_attr_setlong(m_p_text, gensym("size"), 50);
jit_attr_setsym(m_p_text, gensym("drawto"), gensym("test_matrix"));
t_atom_long arr[ 3 ] = { 2, 2, 2 };
jit_attr_setlong_array(m_p_text, gensym("scale"), 3, arr );
float arr2[ 3 ] = { -5, -0.5, 0 };
jit_attr_setfloat_array(m_p_text, gensym("position"), 3, arr2 );
}
if ( !( m_p_render = jit_object_new( gensym( "jit_gl_render" ) ) ) )
m_p_output->err( "Cannot create render" );
else {
jit_attr_setsym(m_p_render, gensym("drawto"), gensym("test_matrix"));
t_atom_long arr[ 4 ] = { 1, 1, 1, 1 };
jit_attr_setlong_array(m_p_render, gensym("erase_color"), 4, arr );
jit_object_method( m_p_text, gensym( "text" ), gensym( "test_text" ) );
jit_object_method( m_p_render, gensym( "erase" ) );
jit_object_method( m_p_render, gensym( "draw" ) );
}
}
hey Lee, you should be able to create a jit.gl.text object (not jit.gl.text2d/3d). the underling jitter object of text2d/3d is jit.gl.text.void *text_2d = jit_object_new( gensym( "jit_gl_text" ) );
for 2d (not necessary as it's the default): jit_attr_setsym(text_2d, gensym("mode"), gensym("2d"));
and for 3d: jit_attr_setsym(text_2d, gensym("mode"), gensym("3d"));
let me know if this doesn't get you going.
hi Rob, thx for the reply... agreed, as you can see from the code snippet above, got that bit figured that out... So i have the text object, a render object, and a matrix - but nothing seems to end up in the matrix... I attach the text object to the matrix, along with the render, as I would do in a patch, and then send an "erase" and a "draw" to the render... at least that's what I think I'm doing... :) Can you see any issues with the above code?
thx
hey lee, please zip together your source code including the project file and i'll be happy to take a look. your posted code is not exactly legible.
hi, do you have somewhere I can send it to then? Yeah, for some reason the forum decided to 'quot' all my quotes...
matrix = jit_object_new(_jit_sym_jit_matrix, &info) );
jit_object_register( matrix, gensym( "test_matrix" ) );
text = jit_object_new( gensym( "jit_gl_text" ) );
jit_attr_setsym(text, gensym( "drawto" ), gensym( "test_matrix" ));
jit_attr_setlong(text, gensym( "size" ), 50);
render = jit_object_new( gensym("jit_gl_render" ) );
jit_attr_setsym(render, gensym( "drawto" ), gensym( "test_matrix" ));
float arr[ 4 ] = { 0.2, 0.4, 1, 1 };
jit_attr_setfloat_array(render, gensym("erase_color"), 4, arr );
jit_object_method( text, gensym( "text" ), gensym( "test_text" ) );
jit_object_method( render, gensym( "erase" ) );
jit_object_method( text, gensym( "bang" ) );
jit_object_method( render, gensym( "draw" ) );
thinking about it, I'm not even getting the matrix filled with the erase colour...
Some progress after a suggestion to look at the Javscript examples, which are documented to a much higher extent than the SDK.
So, I played around and got a simple example working
var mymatrix = new JitterMatrix( 4, "char", 160, 160 );
var render = new JitterObject( "jit.gl.render", mymatrix.name );
var text = new JitterObject( "jit.gl.text", mymatrix.name );
render.erase_color[ 0 ] = 1;
render.erase_color[ 1 ] = 0.5;
render.erase_color[ 2 ] = 1;
render.erase_color[ 3 ] = 0.2;
render.erase();
text.text( "hello" );
text.draw();
render.drawclients();
render.swap();
and changed my C calls to:
jit_object_method( render, gensym( "erase" ) );
jit_object_method( text, gensym( "text" ), gensym( "test_text" ) );
jit_object_method( text, gensym( "draw" ) );
jit_object_method( render, gensym( "drawclients" ) );
jit_object_method( render, gensym( "swap" ) );
No text still, but the background is being erased and drawn in the specified colour....
hey Lee, glad you're making progress. was also going to suggest testing out techniques in javascript.
"text" is a typed method, so you have to use object_method_typed (or jit_object_method_typed, which is an alias)
t_atom a;
jit_atom_setsym(&a, gensym("typed text"));
object_method_typed( text, gensym( "text"), 1, &a, NULL );
make sure you check out all the docs on jitter development, found here:
https://cycling74.com/sdk/MaxSDK-7.0.3/html/pages.html
Hi, thanks! will give it a go - have been reading the SDK docs (seems to be what's a the link you sent).
"Your object's methods are called by Max, but your object can also call methods itself. When you call a method, it is
essential to know whether the method you are calling is typed or not."
What determines if something is typed or not? How do I know that I need to call the text method differently from the others?
thx
any message exported to the max object that takes arguments (check the object ref file for these), is a typed message.
ok, got ya - most illumnating.
whilst hunting around I've also found the jit.mgraphics object which may suit my needs aswell - has better drawing primitive and can just output a matrix which is ultimately what I'm after.
this has been an interesting insight though and most useful - I do think that this simple case is worthy of a quick C example - just having the setup, calling the text and render - with a few notes on a couple of comments on why the text() call is typed and it'll provide an invaluable insight into people wanting to do similar kinds of things... Even though the js helped and you filled in the blanks, someone suggested going to the js in the first place as I was just hunting around the C examples and didn't think of that...
Final solution for those in a similar position:
t_jit_matrix_info info;
info.dimcount = 2;
info.type = _jit_sym_char;
info.planecount = 4;
info.dim[ 0 ] = 320;
info.dim[ 1 ] = 200;
t_symbol *p_matrix_name = gensym( "test_matrix" );
// create matrix, text, and render objects
m_p_matrix = jit_object_new( _jit_sym_jit_matrix, &info );
jit_object_register( m_p_matrix, p_matrix_name );
m_p_text = jit_object_new( gensym( "jit_gl_text" ) );
jit_attr_setsym( m_p_text, gensym("drawto"), p_matrix_name );
m_p_render = jit_object_new( gensym( "jit_gl_render" ) );
jit_attr_setsym( m_p_render, gensym("drawto"), p_matrix_name );
float arr[ 4 ] = { 0.2, 0.2, 0, 1 };
jit_attr_setfloat_array( m_p_render, gensym("erase_color"), 4, arr );
// for anything that requires parameters, use the object_method_typed() call which takes an array of atoms
// use the object reference documentation to see parameters for a call
t_atom a;
jit_atom_setsym( &a, gensym( "example text" ) );
object_method_typed( m_p_text, gensym( "text"), 1, &a, NULL );
jit_atom_setlong( &a, 50 );
object_method_typed( m_p_text, gensym( "size"), 1, &a, NULL );
// erase background, draw the text, render the frame and then swap the buffers
// this sequence of events will cause something to get rendered into the matrix
jit_object_method( m_p_render, gensym( "erase" ) );
jit_object_method( m_p_text, gensym( "draw" ) );
jit_object_method( m_p_render, gensym( "drawclients" ) );
jit_object_method( m_p_render, gensym( "swap" ) );