Advertisement
LordMirai

animated thing

Apr 18th, 2022
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.26 KB | None | 0 0
  1. /*
  2.  Eliminarea fetelor functie de orientare
  3.  Se va afisa fara activarea eliminarii fetelor. Cu orientarea directa
  4.  implicita se vor schimba fetele care se elimina -cele fata sau cele spate-
  5.  cu functia glCullFace.
  6.  Se va activa sau se va dezactiva testul de adancime
  7.  */
  8. #include "glos.h"
  9.  
  10. #include <GL/gl.h>
  11. #include <GL/glu.h>
  12. #include <GL/glaux.h>
  13.  
  14. #include <math.h>
  15.  
  16. void myinit(void);
  17. void CALLBACK myReshape(GLsizei w, GLsizei h);
  18. void CALLBACK display(void);
  19. void CALLBACK IdleFunction(void);
  20. double x = 1;
  21. void CALLBACK IdleFunction(void)
  22. {
  23.     glRotatef(1.1+sin(x), -0.3, 0.9, 0.6);
  24.     display();
  25.     Sleep(40);
  26.     x += 0.2;
  27.  
  28. }
  29.  
  30.  
  31. void myinit(void)
  32. {
  33.  
  34.     glClearColor(0.0, 0.0, 0.0, 1.0);
  35.     glShadeModel(GL_SMOOTH);
  36.     glEnable(GL_DEPTH_TEST);
  37.  
  38. }
  39.  
  40.  
  41. void CALLBACK display(void)
  42. {
  43.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  44.     glColor3f(1.0, 0.0, 0.0);
  45.     //glEnable(GL_CULL_FACE);//activeaza eliminarea fetelor
  46.     //glCullFace(GL_BACK);//sunt eliminate fetele spate
  47.     //inlocuiti cu GL_FRONT pentru fete fata
  48.     //glEnable(GL_DEPTH_TEST);
  49.     glBegin(GL_QUAD_STRIP);
  50.     glColor3f(1.0f, 0.0f, 1.0f);
  51.     glVertex3f(-0.5f, 0.5f, 0.5f);
  52.  
  53.     glColor3f(1.0f, 0.0f, 0.0f);
  54.     glVertex3f(-0.5f, -0.5f, 0.5f);
  55.  
  56.     glColor3f(1.0f, 1.0f, 1.0f);
  57.     glVertex3f(0.5f, 0.5f, 0.5f);
  58.  
  59.     glColor3f(1.0f, 1.0f, 0.0f);
  60.     glVertex3f(0.5f, -0.5f, 0.5f);
  61.  
  62.     glColor3f(0.0f, 1.0f, 1.0f);
  63.     glVertex3f(0.5f, 0.5f, -0.5f);
  64.  
  65.     glColor3f(0.0f, 1.0f, 0.0f);
  66.     glVertex3f(0.5f, -0.5f, -0.5f);
  67.  
  68.     glColor3f(0.0f, 0.0f, 1.0f);
  69.     glVertex3f(-0.5f, 0.5f, -0.5f);
  70.  
  71.     glColor3f(0.0f, 0.0f, 0.0f);
  72.     glVertex3f(-0.5f, -0.5f, -0.5f);
  73.  
  74.     glColor3f(1.0f, 0.0f, 1.0f);
  75.     glVertex3f(-0.5f, 0.5f, 0.5f);
  76.  
  77.     glColor3f(1.0f, 0.0f, 0.0f);
  78.     glVertex3f(-0.5f, -0.5f, 0.5f);
  79.  
  80.     glEnd();
  81.  
  82.     glBegin(GL_QUADS);
  83.     glColor3f(1.0f, 0.0f, 1.0f);
  84.     glVertex3f(-0.5f, 0.5f, 0.5f);
  85.  
  86.     glColor3f(1.0f, 1.0f, 1.0f);
  87.     glVertex3f(0.5f, 0.5f, 0.5f);
  88.  
  89.     glColor3f(0.0f, 1.0f, 1.0f);
  90.     glVertex3f(0.5f, 0.5f, -0.5f);
  91.  
  92.     glColor3f(0.0f, 0.0f, 1.0f);
  93.     glVertex3f(-0.5f, 0.5f, -0.5f);
  94.     glEnd();
  95.  
  96.     glFrontFace(GL_CCW);
  97.     glBegin(GL_QUADS);
  98.  
  99.     glColor3f(1.0f, 0.0f, 0.0f);
  100.     glVertex3f(-0.5f, -0.5f, 0.5f);
  101.  
  102.     glColor3f(1.0f, 1.0f, 0.0f);
  103.     glVertex3f(0.5f, -0.5f, 0.5f);
  104.  
  105.     glColor3f(0.0f, 1.0f, 0.0f);
  106.     glVertex3f(0.5f, -0.5f, -0.5f);
  107.  
  108.     glColor3f(0.0f, 0.0f, 0.0f);
  109.     glVertex3f(-0.5f, -0.5f, -0.5f);
  110.     glEnd();
  111.    
  112.     glColor3f(0.2, 0.01, 0.5);
  113.     auxSolidSphere(0.55);
  114.  
  115.     glFlush();
  116.  
  117.  
  118. }
  119.  
  120. void CALLBACK myReshape(GLsizei w, GLsizei h)
  121. {
  122.     if (!h) return;
  123.     glViewport(0, 0, w, h);
  124.     glMatrixMode(GL_PROJECTION);
  125.     glLoadIdentity();
  126.     gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 3.0, 5.0);
  127.     glMatrixMode(GL_MODELVIEW);
  128.     glLoadIdentity();
  129.     glTranslatef(0.0, 0.0, -4.0);  /*  aduce obiectele in volumul de vizualizare   */
  130. }
  131.  
  132. /*  Main Loop
  133.  */
  134. int main(int argc, char** argv)
  135. {
  136.     auxInitDisplayMode(AUX_SINGLE | AUX_RGB | AUX_DEPTH);
  137.     auxInitPosition(0, 0, 500, 400);
  138.     auxInitWindow("CUB");
  139.     myinit();
  140.     auxReshapeFunc(myReshape);
  141.     auxIdleFunc(IdleFunction);
  142.     auxMainLoop(display);
  143.     return(0);
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement