Problem with rendering

I have created a Sphere tree and am trying to display that using the following code.

void DisplayScene()
{
typedef PassData CommunicateData;
CommunicateData Data;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Compute the Bounding Box and the Centre of the Point Cloud
ComputeBoundingBox(pointlist, Data.BoundingBox, Data.Centre, NumPoints);

Data.eyePosition[0] = 0.0f;
Data.eyePosition[1] = 0.0f;
Data.eyePosition[2] = 10.0f;
Data.eyePosition[3] = 1.0f;


float LookAt[3] = {Data.eyePosition[0], Data.eyePosition[1], Data.eyePosition[2] - 10.0f };

#ifdef CG_RENDERING

buildLookAtMatrix(Data.eyePosition[0], Data.eyePosition[1], 
                  Data.eyePosition[2], LookAt[0], LookAt[1], LookAt[2],
                  0, 1, 0,
                  Data.viewMatrix);

#endif

#ifdef OPENGL_RENDERING
glMatrixMode(GL_MODELVIEW);
gluLookAt(Data.eyePosition[0], Data.eyePosition[1], Data.eyePosition[2], LookAt[0], LookAt[1], LookAt[2], 0, 1, 0);

#endif

  BreadthFirstTraversal(&SpTreeRoot, 0, true, ROOT_LEVEL, 
                                       &DisplaySphereScene, (void *)&Data); 
  glutSolidSphere(3, 40, 40);
  glutSwapBuffers();

}

// void DisplaySphereScene(float position[], float viewMatrix[], float eyePosition[])
bool DisplaySphereScene(SphereTreeNode *node, void *StructureData)
{
// Here we will be sending the Data in the form of a structure.
// Hence we will be typecasting the Structure so as to match the data we get.
typedef PassData Pdata;
float scaleFactor[3];

Pdata *IncomingData = (Pdata *)StructureData;

const float lightPosition[4] = { 5.0f, 10.0f, 0.0f, 1.0f};

#ifdef OPENGL_RENDERING

 glPushMatrix();
   
   glEnable(GL_LIGHT0);
   glLightfv(GL_LIGHT0, GL_AMBIENT, yellow);
   glLightfv(GL_LIGHT0, GL_DIFFUSE, yellow);
   glLightfv(GL_LIGHT0, GL_SPECULAR, red);
   glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);		
	
   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 12);

   glutSolidSphere(3, 40, 40);
 glPopMatrix();

// DrawCube(IncomingData->BoundingBox);

#endif

// Display the Current Node Data
return true;

}

///////////////////////////////////////////////////////////////////////////////

                          End of Code 

///////////////////////////////////////////////////////////////////////////////

The problem I am facing is that my display function using Glut is DisplayScene() above. I then call a tree traversal code which then uses a function pointer to call the DisplaySphereScene() function. The problem is that when I try to display a sphere in the DisplaySphereScene() function it is not displayed. However, a sphere being drawn in the DisplaySphere() function is rendered. I can’t understand why I am not able to render spheres in the DisplaySphereScene() function. I would really appreciate the help.
Thanks

Dear Satyjit,

I am not sure what your BreadthFirstTraversal
Func works.

I think ( if I am correct) your both spheres are getting rendered at the same place.My suggestion is to insert glTranslate( ) with appropriate coordinates between glPushMatrix() and glPopMatrix Calls, so that your sphere in the callback Function gets rendered.

RAJESH.R
NEST,
Trivandrum

Satyajit please use the code tags (from the “Instant UBB Code” section in the posting form) for posting code. It makes it much easier to read code and people will be more willing to read your code and help.