Advertisement
ALTEK

LAB10Zad1

Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #define GLUT_DISABLE_ATEXIT_HACK
  2.  
  3. #include <GL/gl.h>
  4. #include <GL/glu.h>
  5. #include <GL/glut.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. int screenWidth = 600;
  10. int screenHeight = 600;
  11. int fps = 60;
  12.  
  13. GLdouble cameraPos[] = {0.0, 0.0, 25.0};
  14. double baserotation = 180.0;
  15. double rotation = 0.0;
  16.  
  17. GLfloat lightAmb[] = {0.1, 0.1, 0.1, 1.0};
  18. GLfloat lightDif[] = {0.7, 0.7, 0.7, 1.0};
  19. GLfloat lightPos[] = {0, 0, 800, 1.0};
  20. GLfloat lightSpec[] = {1, 1, 1, 1};
  21.  
  22. GLfloat points[4][3] = {
  23. {-5.0, 5.0, 0.0},
  24. {0.0, 0.0, 0.0},
  25. {5.0, -2.0, 0.0},
  26. {7.0, 4.0, 0.0}
  27. };
  28.  
  29. GLuint activePoint = 0;
  30.  
  31. void init(){
  32. glEnable(GL_DEPTH_TEST);
  33. glEnable(GL_POINT_SMOOTH);
  34. glEnable(GL_MAP1_VERTEX_3);
  35. }
  36.  
  37. void display() {
  38. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  39. glClearColor(0.0, 0.0, 0.0, 1.0);
  40. glLoadIdentity ();
  41.  
  42. gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  43.  
  44.  
  45. glColor3f(1.0, 0.0, 0.0);
  46. glPointSize(5);
  47. glBegin(GL_POINTS);
  48. (activePoint != 0) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  49. glVertex3fv(points[0]);
  50. (activePoint != 1) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  51. glVertex3fv(points[1]);
  52. (activePoint != 2) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  53. glVertex3fv(points[2]);
  54. (activePoint != 3) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  55. glVertex3fv(points[3]);
  56. glEnd();
  57.  
  58. glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &points[0][0]);
  59. glMapGrid1f(30, 0, 1);
  60. glEvalMesh1(GL_LINE, 0, 30);
  61.  
  62. glFlush ();
  63. glutPostRedisplay();
  64. glutSwapBuffers();
  65. }
  66.  
  67. void reshape(int w, int h) {
  68. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  69. glMatrixMode(GL_PROJECTION);
  70. glLoadIdentity();
  71.  
  72. gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 1.5, 300.0);
  73.  
  74. glMatrixMode(GL_MODELVIEW);
  75. }
  76.  
  77. void keyboard(unsigned char key, int x, int y){
  78. switch(key){
  79. case 27 :
  80. case 'q':
  81. exit(0);
  82. break;
  83. case 32:
  84. ++activePoint %= 4; break;
  85. case 'w':
  86. points[activePoint][1]++; break;
  87. case 's':
  88. points[activePoint][1]--; break;
  89. case 'a':
  90. points[activePoint][0]--; break;
  91. case 'd':
  92. points[activePoint][0]++; break;
  93. }
  94. }
  95.  
  96. void timerfunc(int p){
  97. rotation += 0.3;
  98.  
  99. glutPostRedisplay();
  100. glutTimerFunc(1000/fps, &timerfunc, 0);
  101. }
  102.  
  103. void menu(int value) {
  104. switch(value) {
  105. case 0:
  106. exit(0);
  107. break;
  108. }
  109. }
  110.  
  111. int main(int argc, char *argv[]) {
  112. glutInit(&argc, argv);
  113. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  114. glutInitWindowSize(screenWidth, screenHeight);
  115. glutCreateWindow(argv[0]);
  116. glutDisplayFunc(display);
  117. glutReshapeFunc(reshape);
  118. glutKeyboardFunc(keyboard);
  119. glutTimerFunc(1000/fps, &timerfunc, 0);
  120.  
  121. glutCreateMenu(menu);
  122. glutAddMenuEntry("Wyjscie", 0);
  123.  
  124. glutAttachMenu(GLUT_RIGHT_BUTTON);
  125.  
  126. init();
  127.  
  128. glutMainLoop();
  129.  
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement