/********************************/ /* Lighting example */ /* (C) Bedrich Benes 2000 */ /********************************/ #include #include #include #include #define MAX 10 #define AMPLITUDE 0.05 #define FREQUENCY 15 void Reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -100, 100);//working area is ... } void Init() { GLfloat spec[]={1,1,1}; GLfloat diff[] ={1,1,0}; GLfloat pos[] ={1,1,1}; glEnable(GL_AUTO_NORMAL) ; glClearColor(0.1,0.1,0.1,1); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diff); glLightfv(GL_LIGHT0, GL_SPECULAR, spec); glLightfv(GL_LIGHT0, GL_POSITION, pos); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -100, 100);//working area is ... printf("q to quit\n"); } GLfloat f(GLfloat x, GLfloat z, GLfloat t) { return(AMPLITUDE*sin(x*FREQUENCY+t)-0.5); return(0); } void Normf(GLfloat x, GLfloat z, GLfloat t, GLfloat *nx, GLfloat *ny, GLfloat *nz) { GLfloat size; *nx = -AMPLITUDE*FREQUENCY*cos(x*FREQUENCY+t); *ny = 1; *nz = 0; size = (*nx * *nx+ *ny * *ny + *nz * *nz); size=sqrt(size); *nx /= size; *ny /= size; *nz /= size; } void DisplayWave() { int i,j; GLfloat x,y,z; GLfloat nx,ny,nz; static GLfloat t; t += 0.1; glBegin(GL_TRIANGLES); for (i=0;i360) i=0; DisplayWave(); glutSwapBuffers(); } void Idle(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(45,1,1,1); DisplayScene(); } void Display(void) { } //keyboard hit causes the program to exit void Kbd(unsigned char a, int x, int y) { switch(a) { case 'q': exit(0);break; } Display(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutCreateWindow("Sinusoidal wave"); glutDisplayFunc(Display); glutIdleFunc(Idle); glutReshapeFunc(Reshape); glutKeyboardFunc(Kbd); Init(); glutMainLoop(); return 0; }