Advertisement
Shishu

c++ code in visual basic

Feb 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.27 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_POLYGON);
  27.     glColor3f(1, 0, 0);
  28.     glVertex3f(-0.6, -0.75, 0);
  29.     glColor3f(0, 1, 0);
  30.     glVertex3f(0.6, -0.75, 0);
  31.     glColor3f(0, 0, 1);
  32.     glVertex3f(0, 0.75, 0);*/
  33.  
  34.     /*glBegin(GL_TRIANGLES);
  35.     glColor3f(0.5, 0.5, 0.5);
  36.     glVertex3f(0, 0, 0);
  37.     glVertex3f(1, .2, 1);
  38.     glVertex3f(-.5, .5, 2);*/
  39.  
  40.     glBegin(GL_TRIANGLES);
  41.     glColor3f(1.0, 0.0, 0.0);
  42.  
  43.     glVertex3f(0.0, 1.0, 0);
  44.     glVertex3f(-0.5, 0.5, 0.0);
  45.     glVertex3f(0.5, 0.5, 0.0);
  46.    
  47.     glEnd();
  48.  
  49.  
  50.     glBegin(GL_QUADS);
  51.     glColor3f(0.0, 1.0, 0.0);
  52.     glVertex3f(-0.5, -0.5, 0.0);
  53.     glVertex3f(-0.5, 0.5, 0.0);
  54.     glVertex3f(0.5, 0.5, 0.0);
  55.     glVertex3f(0.5, -0.5, 0.0);
  56.     glEnd();
  57.  
  58.     glBegin(GL_QUADS);
  59.     glColor3f(0.0, 0.0, 1.0);
  60.     glVertex3f(-0.2, -0.5, 0.0);
  61.     glVertex3f(-0.2, 0.2, 0.0);
  62.     glVertex3f(0.2, 0.2, 0.0);
  63.     glVertex3f(0.2, -0.5, 0.0);
  64.     glEnd();
  65.  
  66.  
  67.     /*glBegin(GL_QUADS);
  68.     glColor3f(0.0, 0.1, 1.0);
  69.     glVertex3f(-0.5, -0.5, 0.0);
  70.     glVertex3f(-0.3, -0.3, 0.0);
  71.     glVertex3f(-0.3, 0.3, 0.0);
  72.     glVertex3f(-0.3, 0.1, 0.0);*/
  73.  
  74.     glEnd();
  75.     /*glBegin(GL_TRIANGLE_FAN);
  76.          glColor3f(1,0,0);
  77.          glVertex2f(0,0.5);
  78.          glVertex2f(-0.4,0);
  79.          glVertex2f(0.4,0);
  80.          glVertex2f(0,-0.5);
  81.     */
  82.  
  83.     glEnd();
  84. }
  85.  
  86. void display (void) {
  87.  
  88.     // clearing the window with black color, 1st 3 parameter are for R,G,B. last one for opacity
  89.     glClearColor (0.0,0.0,0.0,1.0);
  90.     glClear (GL_COLOR_BUFFER_BIT);
  91.     glLoadIdentity();  
  92.          //viewing transformation
  93.     //glulookat() positions the camera towards the object
  94.     //camera position, camera target, upvector
  95.     gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  96.     shapes();
  97.     glFlush();
  98. }
  99.  
  100. void reshape (int w, int h) {
  101.  
  102.     // 1st 2 parameters for lower left corner of the viewport rectangle. the default is 0,0
  103.     // the next coordinates are width and hight of the viewport
  104. //Set the viewport to be the entire window
  105.     glViewport (0, 0, (GLsizei)w, (GLsizei)h);
  106.  
  107.     // setting the camera
  108.     glMatrixMode (GL_PROJECTION);
  109.     glLoadIdentity ();  
  110.  
  111.     //perspective transform
  112.     //gluPerspective (30, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
  113.     gluPerspective (30, 1, 1.0, 100.0);
  114.     glMatrixMode (GL_MODELVIEW); //switch back the the model editing mode.
  115.  
  116. }
  117.  
  118. int main (int argc, char **argv) {
  119.     glutInit (&argc, argv);
  120.     glutInitDisplayMode (GLUT_SINGLE); // single buffering.. (double buffering for animation)
  121.     // full screen is 1000,1000
  122.     // this 0,0 or 1000,1000 are world co ordinates
  123.     glutInitWindowSize (700, 700);
  124.     glutInitWindowPosition (100, 100);
  125.     glutCreateWindow ("A basic OpenGL Window");
  126.     // registering callback functions
  127.     glutDisplayFunc (display);  
  128.     glutReshapeFunc (reshape);
  129.    
  130.     glutMainLoop ();
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement