Jump to content
  • Advertisement
Sign in to follow this  
ninjahamster

OpenGL Scene graph problems

This topic is 3792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!