Jit.gl.sketch controlling question
Dear forum,
I'm currently adding about 100 interactive objects to my scene. I'm using [jit.gl.sketch] with manual depth sorting to draw existing objects, so ideally I'd like to draw the 100 new objects from the sketch cmdlist in some way.
Would be nice to have the 100 objects in a [jit.gl.multiple], but the problem with this is that I need more control over each object than multiple can give me. Not only position, rotation, scale and texture, but also several parameters to the associated shader that are used for interaction states etc. So I guess multiple is out.
Currently I'm drawing them manually by banging a single [jit.gl.gridshape] 100 times and setting the other params in between. However, when I want to add this to my sketch list, I cannot set the other parameters. The alternative is to make 100 separate [jit.gl.gridshape] objects and add all of those to sketch, but I'm trying to keep memory usage to a minimum as we're already battling the 2GB limit. Does anyone know a more efficient way? Is it possible in some way to 'break' out of sketch in the middle of a cmd list?
Thanks, Bas van der Graaff
I am not sure if this is useful or not:
http://emmanuelflores.wordpress.com/2010/12/21/going-oop-with-jitter-java/
maybe you can have a java class that define each one of your objects and then create them on a main class.
let me know how it goes!
-emmanuel
Hmm, might be a good time to start doing stuff like this some way other than straight Max indeed. Will take me a bit of time to start up and get accustomed to though, so I'm not sure whether I should start on it straight away. But thanks for that page, skimmed over it, there's no GL stuff in there but maybe I should be able to put that in myself :P.
Hey Bas:
I find using java quite useful for creating things like particle systems or so. It is rather flexible and the syntax is quite straight forward.
In the case you want to use gl commands inside java, you can check the API, there are some methods that might be useful. On the other hand you can think in terms of spreading your data between a matrix calculation and its translation into gl commands using the jit.gl.sketch.
let me know any progress!
-emmanuel
For things like this, where you need individual control over lots of things in a jit.gl.sketch situation, some sort of procedural code (JS,Java,C, Lua) is going to be a lot more conceptually satisfying. Attached is an example of using JavaScript to manage drawing a bunch of planes while altering the params of an attached shader. Hope this helps.
@Bas:
just one more comment over the example i sent you. THERE IS, actually, gl stuff on it but it is being exposed on the max patcher(the gl commands). Think on the next terms:
java class -> generates the objects and their coordinates
sketch object -> takes the matrix data and draw in on the context(you can even use glVertex commands there!)
@Andrew: cool example!
hey andrew,
really cool example !
perhaps something for the toolbox section ;-)
d.
Thanks for that example, Andrew!
It does the stuff I need, however, it's still going to be an uphill battle for me. I put in a Sketch object and I can do normal stuff with that, so far so good. With my Max Sketch objects, i've been using the command 'capture mytexture' to be able to draw to a custom buffer texture. But this command doesn't show up in the sketch help, sketch documentation, or anywhere else around jit.gl.render, and when I try it in JS, my window output does disappear, and starts to display random parts of my desktop sometimes. But I can't find any data in the specified texture. Do you guys think it's a good idea to be trying this at all?
I'm sorry, I've always been bad at figuring out stuff like this. It just seems like a big mess sometimes, and since you get next to 0 error messages, when something doesn't work i'm easily at a loss about what to do. Maybe Java would be a little more strict and therefore easier to figure out?
capture is an attribute, so make sure you are setting it correctly.
something like mysketch.capture = "capture_texture";
Hmm, I'm trying in Java now, getting a little bit further. I can replicate what I used to do in Max with sketch, now i'm trying to get rid of sketch. I'm trying to get it to render different objects to different textures, just like you could when using multiple sketches with the capture attribute. Below is a stripped down version of my render method.
Is it possible to set a texture as the destination of an object? Even though I did get some error messages stating my drawto attribute should point to a window, pwindow, matrix or texture, I don't understand how to point it to a texture. The other 3 have their own render context, texture hasn't. Sorry for asking all these questions, but I can't find much info on this subject (and of Jitter in Java in general), so any help is much appreciated.
public void bang()
{
render.send("erase");
for (int i=0;i
{
playerObjects[objList[i].getInt()].setAttr("drawto", "myTexture");
playerObjects[objList[i].getInt()].send("draw");
}
colorPlane.send("draw"); //has myTexture set as texture
render.send("drawclients");
render.send("swap");
}
Hi Bas,
For the next version of Jitter we're working on making it easier to group and manage rendering to texture. Sorry that this is a tricky thing to accomplish currently. For the meantime, there's a few things worth noting on this thread:
- sketch capturing to texture. As highlighted by an off forum email message. Sketch and capturing doesn't work with immediate mode.
- any object, not just sketch, is captured to a texture by setting the capture attribute, not the draw to. However this can present a problem for capturing multiple objects to the same texture, or the same object multiple times.
The current way I would recommend around both of these issues would be to use the little known begin_capture and end_capture messages to jit.gl.texture, in conjunction with the also little known jit.gl.object's drawimmediate method. Below is an example Javascript, which should translate to Java easily.
Hope this helps.
var window = new JitterObject("jit.window", "foo");
var render = new JitterObject("jit.gl.render", "foo");
var gridshape = new JitterObject("jit.gl.gridshape", "foo");
gridshape.automatic = 0;
var sketch = new JitterObject("jit.gl.sketch", "foo");
sketch.automatic = 0;
var texture = new JitterObject("jit.gl.texture", "foo");
texture.dim = [1024, 768];
var videoplane = new JitterObject("jit.gl.videoplane", "foo");
var firsttime = 1;
function bang()
{
if (firsttime) { // initialize once
render.erase();
render.drawswap();
firsttime = 0;
}
// sets our texture as the current context, and erases it
texture.begin_capture();
// let's change the background color
// sketch in immediate mode doesn't work inside the capture
// so instead, we'll use sketch's drawimmediate method
// which uses the current commandlist
sketch.reset();
sketch.glclearcolor(0.1,0.5,0.1,1.);
sketch.glclear();
sketch.glenable("lighting");
sketch.drawimmediate();
// now let's draw our gridshape a few times
// once with lighting enabled, once without
gridshape.position = [1.,1.,0];
gridshape.lighting_enable = 1;
gridshape.drawimmediate();
gridshape.position = [-1.,-1.,0];
gridshape.lighting_enable = 0;
gridshape.drawimmediate();
// finishes capturing
texture.end_capture();
// render the rest of the scene, with our texture on a video plane
render.erase();
videoplane.jit_gl_texture(texture.name);
render.drawswap();
}
Hey Joshua!
Thanks for that, it's exactly what I needed. I remade it in Java yesterday and didn't encounter any trouble, works well! I'd never taken notice of the drawimmediate message (it's fairly hard to spot). But this gives me a lot of control over the order in which things are rendered.
Not everything is clear to me yet, for example, it is possible to use 'camera' and 'lookat' attributes when rendering to multiple textures? Currently it will always use the last value I set it to before I swap, even when I thought I'd already drawn everything unto textures before. I can use the 'draw' message to render in between to make sure the latest set camera position is used, but how exactly this works is beyond me at this point.
More features for this would be awesome, looking forward to it! But I can imagine that it's tricky to provide more control while still keeping it simple enough for people to get into.
And another thing:
Seems I can only do begin_capture and end_capture once per texture per frame. When I try to draw a couple of objects in a loop to multiple textures each, I can only see the output of the last object on the textures. Does begin_capture also clear the target texture?
This means I have to loop through the objects for each texture, which means a lot more setting of params.
How immediate is drawimmediate, really? Maybe this requires a better understanding of how OpenGL works too...