Advertisement
Tusohian

Triangle Task 3

Mar 1st, 2019
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.89 KB | None | 0 0
  1. #include <GL/glut.h>
  2.  
  3. void shapes (void) {
  4.  
  5. /*glColor3f(1.0, 1.0, 1.0); //this will set a color of the square.
  6. glBegin(GL_LINES); // write shape u want to create
  7. glVertex3f(-0.5, -0.5, 0.0);
  8. glVertex3f(-0.5, 0.5, 0.0);
  9. glVertex3f(0.5, 0.5, 0.0);
  10. glVertex3f(0.5, -0.5, 0.0);*/
  11.  
  12. /*glBegin(GL_POINTS);
  13. glVertex3f(.5,.5,0);
  14. glVertex3f(-.5,-.5,0);
  15. glVertex3f(0,.5,0);
  16. glVertex3f(.5,0,0);
  17. glVertex3f(0,0,0);*/
  18.  
  19. /*glBegin(GL_LINE_STRIP);
  20.   glVertex3f(0,0,0);
  21.   glVertex3f(-.5,0,0);  
  22.   glVertex3f(.5,.5,0);
  23.   glVertex3f(-.5,.5,0);
  24.   glVertex3f(.5,0,0);*/
  25.  
  26.     glBegin(GL_TRIANGLES);
  27.     glColor3f(1, .0, 0);
  28.     glVertex3f(0, 0, 0);
  29.     glVertex3f(1, 0, 0);
  30.     glVertex3f(0.5, 1, 0);
  31.  
  32. glBegin(GL_TRIANGLES);
  33.     glColor3f(.5, .0, .1);
  34.     glVertex3f(0.500, 0.0, 0);
  35.     glVertex3f(0.250, .500, 0);
  36.     glVertex3f(0.750, 0.500, 0);
  37.  
  38. glBegin(GL_TRIANGLES);
  39.     glColor3f(1.0, 1.0, 1.0);
  40.     glVertex3f(0.750, 0.0, 0);
  41.     glVertex3f(0.625, .250, 0);
  42.     glVertex3f(0.875, 0.250, 0);
  43.  
  44. glBegin(GL_TRIANGLES);
  45.     glColor3f(1.0, 1.0, 1.0);
  46.     glVertex3f(0.250, 0.0, 0);
  47.     glVertex3f(0.125, .250, 0);
  48.     glVertex3f(0.375, 0.250, 0);
  49.  
  50.  
  51. glBegin(GL_TRIANGLES);
  52.     glColor3f(1.0, 1.0, 1.0);
  53.     glVertex3f(0.500, 0.500, 0);
  54.     glVertex3f(0.375, .750, 0);
  55.     glVertex3f(0.625, 0.750, 0);
  56.  
  57. glBegin(GL_TRIANGLES);
  58.     glColor3f(0.3, 1, 0.0);
  59.     glVertex3f(0.875, 0.0, 0);
  60.     glVertex3f(0.815, .125, 0);
  61.     glVertex3f(0.935, 0.125, 0);
  62.  
  63. glBegin(GL_TRIANGLES);
  64.     glColor3f(0.3, 1, 0.0);
  65.     glVertex3f(0.625, 0.0, 0);
  66.     glVertex3f(0.563, .125, 0);
  67.     glVertex3f(0.688, 0.125, 0);
  68.  
  69.  
  70. glBegin(GL_TRIANGLES);
  71.     glColor3f(0.3, 1, 0.0);
  72.     glVertex3f(0.625, 0.0, 0);
  73.     glVertex3f(0.563, .125, 0);
  74.     glVertex3f(0.688, 0.125, 0);
  75.  
  76. glBegin(GL_TRIANGLES);
  77.     glColor3f(0.3, 1, 0.0);
  78.     glVertex3f(0.750, 0.250, 0);
  79.     glVertex3f(0.688, .375, 0);
  80.     glVertex3f(0.813, 0.375, 0);
  81.  
  82.  
  83. glBegin(GL_TRIANGLES);
  84.     glColor3f(0.3, 1, 0.0);
  85.     glVertex3f(0.250, 0.250, 0);
  86.     glVertex3f(0.188, .375, 0);
  87.     glVertex3f(0.313, 0.375, 0);
  88.  
  89. glBegin(GL_TRIANGLES);
  90.     glColor3f(0.3, 1, 0.0);
  91.     glVertex3f(0.125, 0.0, 0);
  92.     glVertex3f(0.063, .125, 0);
  93.     glVertex3f(0.188, 0.125, 0);
  94.  
  95. glBegin(GL_TRIANGLES);
  96.     glColor3f(0.3, 1, 0.0);
  97.     glVertex3f(0.375, 0.0, 0);
  98.     glVertex3f(0.313, .125, 0);
  99.     glVertex3f(0.438, 0.125, 0);
  100.  
  101. glBegin(GL_TRIANGLES);
  102.     glColor3f(0.3, 1, 0.0);
  103.     glVertex3f(0.375, 0.0, 0);
  104.     glVertex3f(0.313, .125, 0);
  105.     glVertex3f(0.438, 0.125, 0);
  106.  
  107.  
  108. glBegin(GL_TRIANGLES);
  109.     glColor3f(0.3, 1, 0.0);
  110.     glVertex3f(0.375, 0.500, 0);
  111.     glVertex3f(0.313, .625, 0);
  112.     glVertex3f(0.438, 0.625, 0);
  113.  
  114.  
  115. glBegin(GL_TRIANGLES);
  116.     glColor3f(0.3, 1, 0.0);
  117.     glVertex3f(0.625, 0.500, 0);
  118.     glVertex3f(0.563, .625, 0);
  119.     glVertex3f(0.688, 0.625, 0);
  120.  
  121.  
  122. glBegin(GL_TRIANGLES);
  123.     glColor3f(0.3, 1, 0.0);
  124.     glVertex3f(0.500, 0.750, 0);
  125.     glVertex3f(0.438, .875, 0);
  126.     glVertex3f(0.563, 0.875, 0);
  127.  
  128.  
  129.  
  130.  
  131. //int a=6; int b=6; int c=6;
  132. //glBegin(GL_TRIANGLES);
  133.  //   glColor3f(a/4, a/6, a/4);
  134.  //   glVertex3f(-0.6,-0.75,0);
  135.  // glVertex3f(0,0.75,0);
  136.  
  137. /*glBegin(GL_QUADS);
  138. glVertex3f(-0.5, -0.5, 0.0);
  139. glVertex3f(-0.5, 0.5, 0.0);
  140. glVertex3f(0.5, 0.5, 0.0);
  141. glVertex3f(0.5, -0.5, 0.0);*/
  142.  
  143. /*glBegin(GL_TRIANGLE_FAN);
  144.          glColor3f(1,0,0);
  145.          glVertex2f(0,0.5);
  146.          glVertex2f(-0.4,0);
  147.          glVertex2f(0.4,0);
  148.     glVertex2f(0,-0.5);
  149. */
  150.  
  151. glEnd();
  152. }
  153.  
  154. void display (void) {
  155.  
  156. // clearing the window with black color, 1st 3 parameter are for R,G,B. last one for opacity
  157. glClearColor (0.0,0.0,0.0,1.0);
  158.     glClear (GL_COLOR_BUFFER_BIT);
  159.     glLoadIdentity();  
  160.      //viewing transformation
  161. //glulookat() positions the camera towards the object
  162. //camera position, camera target, upvector
  163.     gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  164. shapes();
  165. glFlush();
  166. }
  167.  
  168. void reshape (int w, int h) {
  169.  
  170. // 1st 2 parameters for lower left corner of the viewport rectangle. the default is 0,0
  171. // the next coordinates are width and hight of the viewport
  172. //Set the viewport to be the entire window
  173. glViewport (0, 0, (GLsizei)w, (GLsizei)h);
  174.  
  175. // setting the camera
  176. glMatrixMode (GL_PROJECTION);
  177. glLoadIdentity ();  
  178.  
  179. //perspective transform
  180. //gluPerspective (30, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
  181. gluPerspective (30, 1, 1.0, 100.0);
  182. glMatrixMode (GL_MODELVIEW); //switch back the the model editing mode.
  183.  
  184. }
  185.  
  186. int main (int argc, char **argv) {
  187.     glutInit (&argc, argv);
  188. glutInitDisplayMode (GLUT_SINGLE); // single buffering.. (double buffering for animation)
  189. // full screen is 1000,1000
  190. // this 0,0 or 1000,1000 are world co ordinates
  191. glutInitWindowSize (700, 700);
  192. glutInitWindowPosition (100, 100);
  193.     glutCreateWindow ("A basic OpenGL Window");
  194. // registering callback functions
  195.     glutDisplayFunc (display);  
  196. glutReshapeFunc (reshape);
  197.     glutMainLoop ();
  198.     return 0;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement