Advertisement
Guest User

week9 open gl

a guest
Nov 18th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4.  
  5. #include <stdlib.h>
  6. #include <windows.h>
  7. #include <math.h>
  8.  
  9. float xRotated = 90.0, yRotated = 0.0, zRotated = 0.0;
  10.  
  11. //------------------------------ reshapeFunc ---------------------------------
  12.  
  13. void reshapeFunc (int w, int h)
  14. {
  15. glViewport(0,0,(GLsizei)w,(GLsizei)h);
  16. glMatrixMode(GL_PROJECTION);
  17. glLoadIdentity();
  18. gluPerspective (40.0, (GLdouble)w / (GLdouble)h, 0.5, 20.0);
  19. glMatrixMode(GL_MODELVIEW);
  20. }
  21.  
  22. //------------------------------ display -------------------------------
  23.  
  24. void display (void)
  25. {
  26.  
  27. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  28. glLoadIdentity ();
  29. glTranslatef (0.0, 0.0, -15.0);
  30.  
  31.  
  32.  
  33. glutSwapBuffers();
  34. }
  35.  
  36. //-------------------------------- idleFunc ----------------------------------
  37.  
  38. void idleFunc (void)
  39. {
  40. zRotated += 1;
  41. glutPostRedisplay();
  42. }
  43.  
  44. void texture (void){
  45.  
  46. const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
  47. const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  48. const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  49. const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
  50.  
  51. const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
  52. const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
  53. const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  54. const GLfloat high_shininess[] = { 100.0f };
  55.  
  56. glEnable(GL_CULL_FACE);
  57. glCullFace(GL_BACK);
  58.  
  59. glEnable(GL_DEPTH_TEST);
  60. glDepthFunc(GL_LESS);
  61.  
  62. glEnable(GL_LIGHT0);
  63. glEnable(GL_NORMALIZE);
  64. glEnable(GL_COLOR_MATERIAL);
  65. glEnable(GL_LIGHTING);
  66.  
  67. glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  68. glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  69. glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  70. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  71.  
  72. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  73. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  74. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  75. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  76.  
  77.  
  78. }
  79.  
  80. //---------------------------------- main ------------------------------------
  81.  
  82.  
  83. int main (int argc, char **argv)
  84. {
  85. glutInit (&argc, argv);
  86. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // buffer mode
  87. glutInitWindowSize (800, 700);
  88. glutInitWindowPosition (700, 200);
  89. glutCreateWindow ("Sphere Rotating Animation");
  90.  
  91. glClearColor (1.0, 1.0, 1.0, 0.0);
  92.  
  93. glutDisplayFunc (display);
  94. glutReshapeFunc (reshapeFunc);
  95. glutIdleFunc (idleFunc);
  96.  
  97. glClearColor(1,1,1,1);
  98. texture(); // Lighting and textures
  99.  
  100.  
  101. glutMainLoop();
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement