Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include<gl\glut.h>
  2. GLUquadricObj* theqw;
  3. void drawsphera() {
  4.     GLfloat koort[][2] = { {100, 140}, {120, 120}, {140, 100}, {160, 80} };
  5.     for (int i = 0; i < 4; ++i) {
  6.         if (i == 2) glColor4f(1, 0, 0, 0.2);
  7.         if (i == 1) glColor4f(0, 1, 1, 0.4);
  8.         if (i == 0) glColor4f(0, 0, 1, 0.7);
  9.         if (i == 3) glColor4f(0, 1, 0, 0.9);
  10.         glPushMatrix();
  11.         glTranslatef(koort[i][0], koort[i][1], -50);
  12.         gluSphere(theqw, 40, 50, 50);
  13.         glPopMatrix();
  14.     }
  15. }
  16.  
  17. void init()
  18. {
  19.     glClearColor(1, 1, 1, 1);
  20.     GLfloat lightposition[] = { 0,0,-100,0 };
  21.     theqw = gluNewQuadric();
  22.     glEnable(GL_DEPTH_TEST);
  23.     glLightfv(GL_LIGHT0, GL_POSITION, lightposition);
  24.     glEnable(GL_LIGHTING);
  25.     glEnable(GL_LIGHT0);
  26.     glEnable(GL_COLOR_MATERIAL);
  27.     glEnable(GL_BLEND);
  28.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  29.  
  30. }
  31.  
  32.  
  33. void Display()
  34. {
  35.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  36.     glDepthMask(GL_FALSE);
  37.     drawsphera();
  38.     glDepthMask(GL_TRUE);
  39.     glutPostRedisplay();
  40.     glutSwapBuffers();
  41.  
  42. }
  43.  
  44. void reshape(int w, int h)
  45. {
  46.     glMatrixMode(GL_PROJECTION);
  47.     glLoadIdentity();
  48.     glOrtho(0, 240, 240, 0, 10, 240);
  49.     glMatrixMode(GL_MODELVIEW);
  50.  
  51. }
  52.  
  53. void main() {
  54.     //параметры окна
  55.     glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  56.     //размеры окна
  57.     glutInitWindowSize(240, 240);
  58.     //позиция окна
  59.     glutInitWindowPosition(100, 100);
  60.     //создание окна
  61.     glutCreateWindow(" ");
  62.     //glClearColor(0.9, 0.5, 0.75, 1);
  63.  
  64.     init();
  65.     glutReshapeFunc(reshape);
  66.  
  67.  
  68.     //вывод изображения на экран
  69.     glutDisplayFunc(Display);
  70.     //отображение окна
  71.     glutMainLoop();
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement