View Full Version : Help with scene graph!

08-16-2004, 11:47 PM
Hello. I want to add a scene graph class to my 2d opengl engine, but I am stuck at the very begining. This is the scheme of my scene graph

and I am trying to render all the nodes, but children of node2 are not rendered, moreover the program says firstly there are no children of node2, but then it says it has 2 children nodes, but they are not rendered, untill I explicitly call Node2.render(). Please help!

#include <iostream>
#include <list>
#include <string>

using namespace std;

class Node {


string m_name;

Node() {};
Node(string&amp; name) { m_name = name; };
virtual ~Node() {};

Node *m_parent;

list <Node> listChildren;

static int c;
virtual void setParent(Node* parent)
m_parent = parent;

virtual void render() {

cout << m_name << " is being rendered" << endl;
cout << m_name << " has " << this->listChildren.size() << " children" << endl;

list <Node>::iterator p = this->listChildren.begin();

while ( p != this->listChildren.end()){

cout << p->m_name << " is the child's node of " << m_name << " and will be processed" << endl;


cout << "now getting next child of " << m_name << " or going further" << endl;




int Node::c;

int main ()

Node node1 (string("NODE1"));
Node node2 (string("NODE2"));
Node node3 (string("NODE3"));
Node node4 (string("NODE4"));
Node node5 (string("NODE5"));
Node node6 (string("NODE6"));



cout << node1.c << " children rendered" << endl;

cout << "node 1, children " << node1.listChildren.size() << endl;
cout << "node 2, children " << node2.listChildren.size() << endl;
cout << "node 3, children " << node3.listChildren.size() << endl;
cout << "node 4, children " << node4.listChildren.size() << endl;
cout << "node 5, children " << node5.listChildren.size() << endl;
cout << "node 6, children " << node6.listChildren.size() << endl;

return 0;


08-17-2004, 01:32 AM
static int c;I havent looked at the code in detail but this is very supiscous. Making a member static means all instances of an object will share the same value.

I dont think thats what you wanted it to be.

08-17-2004, 02:56 AM
yes, but this variable is used for debug purposes only :) it shows me the number of children nodes that were rendered.

08-17-2004, 08:08 AM
I see, anyway this:

m_parent->listChildren.push_back(*this);will create a shallow copy of this (meaning the list of the new object is empty) and places that into the list of the parent node. So the parent will have child nodes but those childs arent the ones you think they are.

Because this is a board dedicated to OpenGL programming and not STL programming I will leave it to you to figure out how to fix it :p

08-17-2004, 08:41 AM
Sorry but this has nothing to do with OpenGL.