   printf inside the display function?
  Cant I use printf inside my display function? Im just trying to use it so I can see if Im doing the calculations right.. put in the %d one just to check if there was something wrong with the array..#include <math.h>#include <GL/glut.h>#include <stdio.h>#include <stdlib.h>#define PI 3.1415926535897932384626433832795int light_view = 0;void init(void){    glClearColor (0.0, 0.0, 0.0, 0.0);    glEnable(GL_DEPTH_TEST);}void CalcNormal(float p1[3], float p2[3], float p3[3], float n[3]){    float v1[3], v2[3], length;    const int x = 0;    const int y = 1;    const int z = 2;    // calculate two vectors from given vertices    v1[x] = p2[x] - p1[x];    v1[y] = p2[y] - p1[y];    v1[z] = p2[z] - p1[z];    v2[x] = p3[x] - p1[x];    v2[y] = p3[y] - p1[y];    v2[z] = p3[z] - p1[z];    // calculate cross product of v1 & v2 to get normal    n[0] = v1[y]*v2[z] - v2[y]*v1[z];    n[1] = v1[z]*v2[x] - v2[z]*v1[x];    n[2] = v1[x]*v2[y] - v2[x]*v1[y];    // calculate length of vector    length = (float)sqrt (n[x]*n[x] + n[y]*n[y] + n[z]*n[z]);    // make sure vector is not too close to zero!    if (length == 0.0f)   length = 1.0f;    // normalise vector by dividing by length    n[x] /= length;    n[y] /= length;    n[z] /= length;}void changeView(GLdouble *a){    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    gluLookAt(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);    glutPostRedisplay();}void display(void){    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glPushMatrix();   //bottom of the container   glColor3f(0.0,1.0,0.0);   glBegin(GL_POLYGON);  float n[3];  float p1[] = {-1.5, -1.0, 0.0};  float p2[] = {-1.0, -1.0, 1.0};  float p3[] = {-1.0, -1.0, -1.0};  CalcNormal(p1, p2, p3, n);  printf("%f %f %f", n[0],n[1],n[2]);  printf("%d", 4);  glNormal3fv(n);  glVertex3f(-1.0, -1.0, 1.0);  glVertex3f(-1.5, -1.0, 0.0);  glVertex3f(-1.0, -1.0, -1.0);  glVertex3f(1.0, -1.0, -1.0);  glVertex3f(1.5, -1.0, 0.0);  glVertex3f(1.0, -1.0, 1.0);   glEnd();   glColor3f(1.0,0.0,0.0);   glBegin(GL_POLYGON);  glVertex3f(1.0, 1.0, 1.0);  glVertex3f(1.0, -1.0, 1.0);  glVertex3f(1.5, -1.0, 0.0);  glVertex3f(1.5, 1.0, 0.0);   glEnd();   glBegin(GL_POLYGON);  glVertex3f(-1.0, 1.0, 1.0);  glVertex3f(-1.0, -1.0, 1.0);  glVertex3f(1.0, -1.0, 1.0);  glVertex3f(1.0, 1.0, 1.0);   glEnd();   glBegin(GL_POLYGON);  glVertex3f(-1.5, 1.0, 0.0);  glVertex3f(-1.5, -1.0, 0.0);  glVertex3f(-1.0, -1.0, 1.0);  glVertex3f(-1.0, 1.0, 1.0);   glEnd();   glColor3f(0.0,0.0,1.0);   glBegin(GL_POLYGON);  glVertex3f(-1.0, 1.0, -1.0);  glVertex3f(-1.0, -1.0, -1.0);  glVertex3f(-1.5, -1.0, 0.0);  glVertex3f(-1.5, 1.0, 0.0);   glEnd();   glBegin(GL_POLYGON);  glVertex3f(1.0, 1.0, -1.0);  glVertex3f(1.0, -1.0, -1.0);  glVertex3f(-1.0, -1.0, -1.0);  glVertex3f(-1.0, 1.0, -1.0);   glEnd();   glBegin(GL_POLYGON);  glVertex3f(1.5, 1.0, 0.0);  glVertex3f(1.5, -1.0, 0.0);  glVertex3f(1.0, -1.0, -1.0);  glVertex3f(1.0, 1.0, -1.0);   glEnd();    glPopMatrix();    glutSwapBuffers();    glFlush();}void reshape (int w, int h){    glViewport (0, 0, (GLsizei) w, (GLsizei) h);    glMatrixMode (GL_PROJECTION);    glLoadIdentity ();    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);}void keyboard (unsigned char key, int x, int y){    switch (key) {   case 'v':   case 'V':  light_view = 0;  break;   case 'l':   case 'L':  light_view = 1;  break;   case 'c':   case 'C':  break;   case 'f':   case 'F':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {0.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}; changeView(viewCoordinates);  }  break;   case 'r':   case 'R':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {0.0, 0.0, -8.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}; changeView(viewCoordinates);  }  break;   case 't':   case 'T':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}; changeView(viewCoordinates);  }  break;   case 'b':   case 'B':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {0.0, -8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}; changeView(viewCoordinates);  }  break;   case 'p':   case 'P':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {-8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}; changeView(viewCoordinates);  }  break;   case 's':   case 'S':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}; changeView(viewCoordinates);  }  break;   case 'a':   case 'A':  if (light_view == 0)  { GLdouble viewCoordinates[9] = {-1.0, 6.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}; changeView(viewCoordinates);  }  break;   case 27:  exit(0);  break;   default:  break;    }}int main(int argc, char** argv){   glutInit(&argc, argv);   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);   glutInitWindowSize (500, 500);   glutInitWindowPosition (500, 500);   glutCreateWindow (argv[0]);   init ();   glutDisplayFunc(display);   glutReshapeFunc(reshape);   glutKeyboardFunc(keyboard);   glutMainLoop();   return 0;}
Quote:Original post by NanookCant I use printf inside my display function?Why? Doesn't it work?   ;  nope, its not printing to the terminal :/ everything is drawn and works.. but theres nothing in the terminal window..   ;  hmmm.. now, If I hold down one of the change view keys it starts printing.. but shouldn't just print it every time its drawn? seems like its abit buggy.. might be because its under linux?   ;  Addfflush(stdout);after printf.   ;  that works, thanks..   