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;

// 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 };


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


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


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


// 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};


   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);

// DrawCube(IncomingData->BoundingBox);


// 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.

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.


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.