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!