Advertisement
ALTEK

LAB9Zad

Jun 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. #define GLUT_DISABLE_ATEXIT_HACK
  2. #include "GLee.h"
  3.  
  4. #include <GL/gl.h>
  5. #include <GL/glu.h>
  6. #include <GL/glut.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <time.h>
  11. #include <ctime>
  12.  
  13. #include "Targa.h"
  14.  
  15. int screenWidth = 600;
  16. int screenHeight = 600;
  17. int fps = 60;
  18.  
  19. GLdouble cameraPos[] = {0.0, 0.0, 25.0};
  20. double baserotation = 180.0;
  21. double rotation = 0.0;
  22.  
  23. GLfloat lightAmb[] = {0.1, 0.1, 0.1, 1.0};
  24. GLfloat lightDif[] = {0.7, 0.7, 0.7, 1.0};
  25. GLfloat lightPos[] = {0, 0, 800, 1.0};
  26. GLfloat lightSpec[] = {1, 1, 1, 1};
  27.  
  28. GLuint tex;
  29.  
  30. void init(){
  31. glEnable(GL_DEPTH_TEST);
  32. glEnable(GL_POINT_SMOOTH);
  33. glEnable(GL_TEXTURE_2D);
  34. glEnable(GL_TEXTURE_CUBE_MAP_ARB);
  35. glEnable(GL_TEXTURE_GEN_S);
  36. glEnable(GL_TEXTURE_GEN_T);
  37. glEnable(GL_TEXTURE_GEN_R);
  38.  
  39. glGenTextures(1, &tex);
  40.  
  41. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
  42. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  43. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
  44. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
  45. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_REPEAT);
  46.  
  47. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
  48. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
  49. glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
  50.  
  51. glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, tex);
  52. LoadTGAMipmap("textures/right.tga", GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB);
  53. LoadTGAMipmap("textures/left.tga", GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB);
  54. LoadTGAMipmap("textures/top.tga", GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB);
  55. LoadTGAMipmap("textures/bottom.tga", GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB);
  56. LoadTGAMipmap("textures/near.tga", GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB);
  57. LoadTGAMipmap("textures/far.tga", GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
  58.  
  59. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  60. }
  61.  
  62. void display() {
  63. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  64. glClearColor(0.0, 0.0, 0.0, 1.0);
  65. glLoadIdentity ();
  66.  
  67. gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  68.  
  69. glMatrixMode(GL_TEXTURE);
  70. glLoadIdentity();
  71. glRotatef(baserotation, 0, 1, 0);
  72. glRotatef(rotation, 0, 1, 0);
  73.  
  74. glMatrixMode(GL_MODELVIEW);
  75. glutSolidSphere(3, 30, 30);
  76.  
  77. glMatrixMode(GL_TEXTURE);
  78. glLoadIdentity();
  79. glRotatef(rotation, 0, 1, 0);
  80.  
  81. glMatrixMode(GL_MODELVIEW);
  82. glutSolidSphere(3, 30, 30);
  83.  
  84. glutSolidSphere(200, 50, 50);
  85.  
  86. glFlush ();
  87. glutPostRedisplay();
  88. glutSwapBuffers();
  89. }
  90.  
  91. void reshape(int w, int h) {
  92. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  93. glMatrixMode(GL_PROJECTION);
  94. glLoadIdentity();
  95.  
  96. gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 1.5, 300.0);
  97.  
  98. glMatrixMode(GL_MODELVIEW);
  99. }
  100.  
  101. void keyboard(unsigned char key, int x, int y){
  102. switch(key){
  103. case 27 :
  104. case 'q':
  105. exit(0);
  106. break;
  107. }
  108. }
  109.  
  110. void timerfunc(int p){
  111. rotation += 0.3;
  112.  
  113. glutPostRedisplay();
  114. glutTimerFunc(1000/fps, &timerfunc, 0);
  115. }
  116.  
  117. void menu(int value) {
  118. switch(value) {
  119. case 0:
  120. exit(0);
  121. break;
  122. }
  123. }
  124.  
  125. int main(int argc, char *argv[]) {
  126. srand(time(NULL));
  127. glutInit(&argc, argv);
  128. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  129. glutInitWindowSize(screenWidth, screenHeight);
  130. glutCreateWindow(argv[0]);
  131. glutDisplayFunc(display);
  132. glutReshapeFunc(reshape);
  133. glutKeyboardFunc(keyboard);
  134. glutTimerFunc(1000/fps, &timerfunc, 0);
  135.  
  136. glutCreateMenu(menu);
  137. glutAddMenuEntry("Wyjscie", 0);
  138.  
  139. glutAttachMenu(GLUT_RIGHT_BUTTON);
  140.  
  141. init();
  142.  
  143. glutMainLoop();
  144.  
  145. return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement