i have this piece of code. Can anyone please help me to decipher what i’m doing wrong?
I am reading from my linked list, to determine which atom the user has selected, and then to correspondingly render the chosen molecule ontot the screen. i do this by using a switch statement in my glut display.
either i have something horrendously wrong in my code or i can not do this. could someone please advise?
the error which appears is segmentation fault?
but why?
the LINK is a global variable which is a pointer to my struct.
//
/*function display produces a sphere which is called by all three when rendering */
//
void display(void)
{
LINK temp1, temp2;
int i, j;
GLUquadricObj *qobj;
qobj=gluNewQuadric();
i=0;
j=0;
glClearColor(.9f,.9f,.9f,1.0f);
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
temp2=temp1;
for(i=0;temp2!=NULL;i++)
{
printf("
i am in the while loop");
switch (temp2->element) /*Beggininning of the switch statement to allow the user to*/
/*recognise valid input*/
{
case'N':
printf("This means that you have selected a Nitrogen atom
");
glPushMatrix();
glRotatef(rotationY,0.0,1.0,0.0);
glRotatef(rotationX,1.0,0.0,0.0);
glScalef(scale, scale, scale);
glTranslatef(0.0, 0.0, 0.0);
glColor3fv(nitrogenCol);
glutSolidSphere (0.20, segments,segments );
glPopMatrix();
glPushMatrix();
/glRotatef(-90.0,0.0,1.0,0.0);/
glRotatef(rotationY,0.0,1.0,0.0);
glRotatef(rotationX,1.0,0.0,0.0);
glScalef(scale, scale, scale);
glTranslatef(0.0,0.0,0.0);
gluCylinder(qobj,0.05,0.05,1.0,20.0,10.0);
glPopMatrix();
break;
case'O':
printf("This means that you have selected an Oxygen atom
");
// glPushMatrix();
glRotatef(rotationY,0.0,1.0,0.0);
glRotatef(rotationX,1.0,0.0,0.0);
glScalef(scale, scale, scale);
glTranslatef(-1.0, 0.0, 0.0);
glColor3fv(oxygenCol);
glutSolidSphere (0.20, segments, segments);
glPopMatrix();
glPushMatrix();
glRotatef(rotationY,0.0,1.0,0.0);
glRotatef(rotationX,1.0,0.0,0.0);
glScalef(scale, scale, scale);
glRotatef(-90.0,0.0,1.0,0.0);
glTranslatef(0.0,0.0,0.0);
gluCylinder(qobj,0.05,0.05,1.0,20.0,10.0);
glPopMatrix();
break;
case'C':
printf("This means that you have selected another wanky carbon atom
");
glPushMatrix();
glRotatef(rotationY,0.0,1.0,0.0);
glRotatef(rotationX,1.0,0.0,0.0);
glScalef(scale, scale, scale);
glTranslatef(1.0, 0.0, 0.0);
glColor3fv(carbonCol);
glutSolidSphere (0.20,segments, segments);
glPopMatrix();
break;
} /*End of switch statement*/
temp2=temp2->next;
} /*end of for loop*/
glRasterPos2i(-2,-2);
int k;
for(k=0;k<(int)strlen(text);k++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,text[k]);
}
glutSwapBuffers();
}