Scene graph problems

Started by
2 comments, last by ninjahamster 15 years, 9 months ago
Hi, i'm trying to implement my own scene graph and i can't see what I'm doing wrong. I've gotten tons of help from the articles here on gamedev but when I try to actually draw it in OpenGL i'm getting problems that i can't seem to solve myself. Everything compiles but the plane starts flickering and then the window goes all black. All the relations are working and I'm thinking it has to be that I'm using my own transformations instead of the glTranslate's and so on. Using GLUT on my Mac, this is my draw-function. The printMatrix keeps printing the identity matrix since I haven't done and transformations on it here.

GLvoid DrawGLScene(GLvoid)
{    
	
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The View
	
	root = new DOFNode("root");
	DOFNode* dn = new DOFNode("dn");
	GeometryNode* gn = new GeometryNode("gn");
	
	root->addChild(dn);
	dn1->addChild(gn);
	dn1->getMatrix().printMatrix();
	
	root->update();
	
    glutSwapBuffers();
}
DOFNode and GeometryNode inherits from the base class Node

void Node::update()
{
	for( std::vector<Node*>::iterator it = childList.begin();
         it != childList.end(); it++ )
    {
	  (*it)->update();
    }
}
matrix is of the type 'Matrix4' and m is a two-dimensional float with the values

void DOFNode::update()
{
	glPushMatrix();
    glLoadMatrixf((float*)matrix.m);
	Node::update();
	glPopMatrix();
}

void DOFNode::translate(float tx, float ty, float tz)
{
	matrix = matrix * Matrix4::getTrans(tx, ty, tz);
}
Finally the update-function in GeometryNode

void GeometryNode::update()
{
	glBegin(GL_QUADS);						// Draw A Quad
		glVertex3f(-1.0f, 1.0f, 0.0f);				// Top Left
		glVertex3f( 1.0f, 1.0f, 0.0f);				// Top Right
		glVertex3f( 1.0f,-1.0f, 0.0f);				// Bottom Right
		glVertex3f(-1.0f,-1.0f, 0.0f);				// Bottom Left
	glEnd();						// Done Drawing The Quad
	
	Node::update();
}
I'm thankful for all help!
Advertisement
first of all, I hope that is not the whole DrawGLScene that you have posted here. If you have have a major memory leak problem because during each frame that you render you allocate new memory for two DOFNode's and one GeometryNode but you never clear it before exiting your function.

I have a working implementation of a scene graph on my website that you can have a look at to see how I did it.
Lazy as I am, I haven't written the destructors yet, but I promise I will!

Thanks for the heads-up on the page. On my way over there now...
Oh dagnabbit, my credits wont get me to the scene management stuff :( I was hoping for a answer I wont have to pay for :) Oh well, back to work...

This topic is closed to new replies.

Advertisement