FaisalAhemdBijoy

GL N

Apr 11th, 2021
432
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * GLUT Shapes Demo
  3.  *
  4.  * Written by Nigel Stewart November 2003
  5.  *
  6.  * This program is test harness for the sphere, cone
  7.  * and torus shapes in GLUT.
  8.  *
  9.  * Spinning wireframe and smooth shaded shapes are
  10.  * displayed until the ESC or q key is pressed.  The
  11.  * number of geometry stacks and slices can be adjusted
  12.  * using the + and - keys.
  13.  */
  14.  
  15. #include<windows.h>
  16. #include <GL/glut.h>
  17. #include<GL/gl.h>
  18. //#include<windows.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21.  
  22. double Txval=0,Tyval=0,sval=0,rotat=0;
  23. bool flagScale=true;
  24. int windowWidth=1000,windowHeight=1000;
  25.  
  26. void rectangle()
  27. {
  28.     glBegin(GL_POLYGON);//Denotes the beginning of a group of vertices that define one or more primitives.
  29.     glColor3f(0.0,1.0,0.0);
  30.     glVertex2f(0.0,1.0);
  31.     glColor3f(0.0,1.0,0.0);
  32.     glVertex2f(2.0,1.0);
  33.     glColor3f(1.0,0.0,0.0);
  34.     glVertex2f(2.0,0.0);
  35.     glColor3f(1.0,0.0,0.0);
  36.     glVertex2f(0.0,0.0);
  37.     glEnd();    //Terminates a list of vertices that specify a primitive initiated by glBegin.
  38.  
  39. }
  40. void cube()
  41. {
  42.     glBegin(GL_QUADS);                // Begin drawing the color cube with 6 quads
  43.     // Top face (y = 1.0f)
  44.     // Define vertices in counter-clockwise (CCW) order with normal pointing out
  45.  
  46.   glColor3f(0.0f, 1.0f, 0.0f);     // Green
  47.       glVertex3f( 1.0f, 1.0f, -1.0f);
  48.       glVertex3f(-1.0f, 1.0f, -1.0f);
  49.       glVertex3f(-1.0f, 1.0f,  1.0f);
  50.       glVertex3f( 1.0f, 1.0f,  1.0f);
  51.  
  52.       // Bottom face (y = -1.0f)
  53.       glColor3f(1.0f, 0.5f, 0.0f);     // Orange
  54.       glVertex3f( 1.0f, -1.0f,  1.0f);
  55.       glVertex3f(-1.0f, -1.0f,  1.0f);
  56.       glVertex3f(-1.0f, -1.0f, -1.0f);
  57.       glVertex3f( 1.0f, -1.0f, -1.0f);
  58.  
  59.       // Front face  (z = 1.0f)
  60.       glColor3f(1.0f, 0.0f, 0.0f);     // Red
  61.       glVertex3f( 1.0f,  1.0f, 1.0f);
  62.       glVertex3f(-1.0f,  1.0f, 1.0f);
  63.       glVertex3f(-1.0f, -1.0f, 1.0f);
  64.       glVertex3f( 1.0f, -1.0f, 1.0f);
  65.  
  66.       // Back face (z = -1.0f)
  67.       glColor3f(1.0f, 1.0f, 0.0f);     // Yellow
  68.       glVertex3f( 1.0f, -1.0f, -1.0f);
  69.       glVertex3f(-1.0f, -1.0f, -1.0f);
  70.       glVertex3f(-1.0f,  1.0f, -1.0f);
  71.       glVertex3f( 1.0f,  1.0f, -1.0f);
  72.  
  73.       // Left face (x = -1.0f)
  74.       glColor3f(0.0f, 0.0f, 1.0f);     // Blue
  75.       glVertex3f(-1.0f,  1.0f,  1.0f);
  76.       glVertex3f(-1.0f,  1.0f, -1.0f);
  77.       glVertex3f(-1.0f, -1.0f, -1.0f);
  78.       glVertex3f(-1.0f, -1.0f,  1.0f);
  79.  
  80.       // Right face (x = 1.0f)
  81.       glColor3f(1.0f, 0.0f, 1.0f);     // Magenta
  82.       glVertex3f(1.0f,  1.0f, -1.0f);
  83.       glVertex3f(1.0f,  1.0f,  1.0f);
  84.       glVertex3f(1.0f, -1.0f,  1.0f);
  85.       glVertex3f(1.0f, -1.0f, -1.0f);
  86.  
  87.  
  88.  
  89.     glEnd();
  90.  
  91. }
  92. void display(void)
  93. {
  94.     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  95.  
  96.     glMatrixMode( GL_PROJECTION );
  97.     glLoadIdentity();
  98.     glOrtho(-8, 8, -8, 8,-8,8);
  99.  
  100.     glMatrixMode( GL_MODELVIEW );
  101.     glLoadIdentity();
  102.     glRotated(45,0,1,0);
  103.     glRotated(45,1,0,0);
  104.     glRotatef(rotat,1,0,1);
  105.     cube();
  106.     glFlush();
  107.     glutSwapBuffers();
  108. }
  109. void myKeyboardFunc( unsigned char key, int x, int y )
  110. {
  111.     switch ( key )
  112.     {
  113.     case 'r':
  114.         Txval+=0.2;
  115.         break;
  116.     case 'l':
  117.         Txval-=0.2;
  118.         break;
  119.     case 'u':
  120.         Tyval+=0.2;
  121.         break;
  122.     case 'd':
  123.         Tyval-=0.2;
  124.         break;
  125.     case 's':
  126.         flagScale=true;
  127.         break;
  128.     case 'a':
  129.         flagScale=false;
  130.         break;
  131.     case 27:    // Escape key
  132.         exit(1);
  133.  
  134.     }
  135.     glutPostRedisplay();
  136. }
  137.  
  138.  
  139. void animate()
  140. {
  141.     if (flagScale == true)
  142.     {
  143.         rotat+=1;
  144.         if(rotat > 360)
  145.             rotat = 0;
  146.     }
  147.     glutPostRedisplay();
  148. }
  149.  
  150. int main (int argc, char **argv)
  151. {
  152.     glutInit(&argc, argv);
  153.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  154.  
  155.     glutInitWindowPosition(0,0);
  156.     glutInitWindowSize(windowWidth,windowHeight);
  157.     glutCreateWindow("Traingle-Demo");
  158.  
  159.     glShadeModel( GL_SMOOTH );
  160.     glEnable( GL_DEPTH_TEST );
  161.     glutDisplayFunc(display);
  162.     glutKeyboardFunc(myKeyboardFunc);
  163.     glutIdleFunc(animate);
  164.  
  165.  
  166.     glutMainLoop();
  167.  
  168.     return 0;
  169. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×