Canvas troubleshooting: Difference between revisions

Jump to navigation Jump to search
m
Line 438: Line 438:
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color"));
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color"));
var root = myCanvas.createGroup();
var root = myCanvas.createGroup();
 
var group = root.createChild('group', 'level:0');
var group = root.createChild('group');
for (var i=0;i<=5;i+=1) {
for (var i=0;i<=5;i+=1) {
 
var textNode = group.createChild("text")
var textNode = group.createChild("text")
         .setText("text node in group #1"~i)
         .setText("=>text node in group # "~i)
         .setTranslation(20, 200)
         .setTranslation(20+i*5, 60+i*15)
         .set("alignment", "left-center")
         .set("alignment", "left-center")
         .set("character-size", 15)
         .set("character-size", 12)
         .set("font", "LiberationFonts/LiberationSans-Bold.ttf")
         .set("font", "LiberationFonts/LiberationSans-Bold.ttf")
         .set("fill", "#ff0000");
         .set("fill", "#ff0000");
group = group.createChild('group', 'level:'~i+1);
group = group.createChild('group');
}
}
root.dumpSceneGraph('my-little-sg.osg');
</syntaxhighlight>
</syntaxhighlight>


This will create a new group for each text node, added to its parent group.
This will create a new group for each text node, added to its parent group.
Once we inspect the scene graph, we'll see that it contains quite a bit of redundant state.
Once we inspect the scene graph, we'll see that it contains quite a bit of redundant state.
However, this is where osg::Optimizer[http://trac.openscenegraph.org/projects/osg//wiki/Support/UserGuides/OptimizerOptions] can shine, by optimizing our scene graph to get rid of redundant state sets and flatten the scene graph.
However, this is where osg::Optimizer[http://trac.openscenegraph.org/projects/osg//wiki/Support/UserGuides/OptimizerOptions] can shine, by optimizing our scene graph to get rid of redundant state sets and flatten the scene graph.

Navigation menu