no errors then run your project.

  •  program
  1. #include<Windows.h>    
  2. // first include Windows.h header file which is required    
  3. #include<stdio.h>    
  4. #include<gl/GL.h>   // GL.h header file    
  5. #include<gl/GLU.h> // GLU.h header file    
  6. #include<gl/glut.h>  // glut.h header file from freeglut\include\GL folder    
  7. #include<conio.h>    
  8. #include<stdio.h>    
  9. #include<math.h>    
  10. #include<string.h>    
  11. // Init_OpenGL() function    
  12. void Init_OpenGL()    
  13. {    
  14.     // set background color to Black    
  15.     glClearColor(0.0, 0.0, 0.0, 0.0);    
  16.     // set shade model to Flat    
  17.     glShadeModel(GL_FLAT);    
  18. }    
  19.     
  20. // Display_Objects() function    
  21. void Display_Objects(void)    
  22. {    
  23.     // clearing the window or remove all drawn objects    
  24.     glClear(GL_COLOR_BUFFER_BIT);    
  25.     /*glPushMatrix(), which copies the current matrix and adds  
  26.     the copy to the top of the stack, and  
  27.     glPopMatrix(), which discards the top matrix on the stack*/    
  28.     glPushMatrix();    
  29.     //the glTranslatef() routine in the display list alters the position of the next object to be drawn    
  30.     glTranslatef(0.0, 0.0, 0.0);    
  31.     // set color to object glColor3f(red,green,blue);    
  32.     glColor3f(1.0, 0.8, 0.0);    
  33.     // draw a wire tea pot    
  34.     glutWireTeapot(1.0);    
  35.     
  36.     // draw a wire sphere    
  37.     glTranslatef(-2.5, 0.0, 0.0);    
  38.     glColor3f(0.0, 1.0, 0.0);    
  39.     glutWireSphere(0.8, 30, 30);    
  40.     
  41.     // draw a wire cone    
  42.     glTranslatef(5.0, 0.0, 0.0);    
  43.     glColor3f(0.0, 0.6, 1.0);    
  44.     glutWireCone(0.8, 1.5, 20, 20);    
  45.     
  46.     // draw a wire cube    
  47.     glTranslatef(-1.0, 1.4, 0.0);    
  48.     glColor3f(1.0, 0.3, 0.0);    
  49.     glutWireCube(1.0);    
  50.     
  51.     // draw a wire torus    
  52.     glTranslatef(-3.0, 0.4, 0.0);    
  53.     glColor3f(1.0, 0.3, 1.0);    
  54.     glutWireTorus(0.2, 0.6, 20, 20);    
  55.     
  56.     // draw a text    
  57.     glTranslatef(-2.5, -4.0, 0.0);    
  58.     
  59.     char str[] = {“OpenGL Demo in Visual C++”};    
  60.     
  61.     glColor3f(1.0, 1.0, 1.0);    
  62.     // set position to text    
  63.     glRasterPos2f(2.0, 0.0);    
  64.     
  65.     for (int i = 0; i < strlen(str); i++)    
  66.     {    
  67.         // draw each character    
  68.         glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, str[i]);    
  69.     }    
  70.     
  71.     //you can draw many objects here like polygons,lines,triangles etc    
  72.     
  73.     glPopMatrix();    
  74.     glutSwapBuffers();    
  75. }    
  76. // Reshape() function    
  77. void Reshape(int w, int h)    
  78. {    
  79.     //adjusts the pixel rectangle for drawing to be the entire new window    
  80.     glViewport(0, 0, (GLsizei)w, (GLsizei)h);    
  81.     //matrix specifies the projection transformation    
  82.     glMatrixMode(GL_PROJECTION);    
  83.     // load the identity of matrix by clearing it.    
  84.     glLoadIdentity();    
  85.     gluPerspective(60.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);    
  86.     //matrix specifies the modelview transformation    
  87.     glMatrixMode(GL_MODELVIEW);    
  88.     // again  load the identity of matrix    
  89.     glLoadIdentity();    
  90.     // gluLookAt() this function is used to specify the eye.    
  91.     // it is used to specify the coordinates to view objects from a specific position    
  92.     gluLookAt(-0.3, 0.5, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);    
  93. }    
  94.     
  95. // main function    
  96. int main(int argc, char** argv)    
  97. {    
  98.     // initialize glut    
  99.     glutInit(&argc, argv);    
  100.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);    
  101.     // set window size    
  102.     glutInitWindowSize(700, 500);    
  103.     // set window location    
  104.     glutInitWindowPosition(250, 50);    
  105.     // create window with window text    
  106.     glutCreateWindow(“OpenGL Demo”);    
  107.     // call Init_OpenGL() function    
  108.     Init_OpenGL();    
  109.     // call glutDisplayFunc() function & pass parameter as Display_Objects() function    
  110.     glutDisplayFunc(Display_Objects);    
  111.     // call glutReshapeFunc() function & pass parameter as Reshape() function    
  112.     glutReshapeFunc(Reshape);    
  113.     //glutMainLoop() is used to redisplay the objects    
  114.     glutMainLoop();    
  115.     return 0;    
  116. }


  • output:-




Leave a comment

Design a site like this with WordPress.com
Get started