Advertisement
Shishu

keyboard in visual basic

Apr 12th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdlib>          // standard definitions
  2. #include <iostream>         // C++ I/O
  3. #include <cstdio>           // C I/O (for sprintf)
  4. #include <cmath>            // standard definitions
  5.  
  6. #include <GL/glut.h>            // GLUT
  7. #include <GL/glu.h>         // GLU
  8. #include <GL/gl.h>          // OpenGL
  9.  
  10. using namespace std;            // make std accessible
  11.  
  12. int r=1,g=1,b=1;
  13. int m=1;
  14. int p=0;
  15.  
  16.  
  17.  
  18.  
  19. void init()
  20. {
  21.     glClearColor(0, 0, 0, 0);      
  22.     glClearDepth(1.0);         
  23.  
  24.     glMatrixMode(GL_PROJECTION);
  25.     glLoadIdentity();
  26.     gluPerspective(60, 1, 1, 1000);
  27.  
  28.     glMatrixMode(GL_MODELVIEW);
  29.     glLoadIdentity();
  30.  
  31.     gluLookAt(             
  32.         0.0, 0.0, 5.0, 
  33.         0.0, 0.0, 0.0,     
  34.         0.0, 1.0, 0.0);
  35.  
  36.     glEnable(GL_DEPTH_TEST);       
  37.  
  38.     glEnable(GL_LIGHTING);     
  39.     glEnable(GL_LIGHT0);       
  40.    
  41.     float lpos[] = { 5, 5, 5, 0 };
  42.     glLightfv(GL_LIGHT0, GL_POSITION, lpos);
  43.  
  44.        
  45.     glShadeModel(GL_SMOOTH);
  46. }
  47.  
  48.  
  49. void display()
  50. {
  51.     glClear(
  52.     GL_COLOR_BUFFER_BIT |      
  53.     GL_DEPTH_BUFFER_BIT);  
  54.  
  55.     glPushMatrix();        
  56.  
  57.     glRotated(0, 1, 0, 0);
  58.  
  59.  
  60.     glEnable(GL_COLOR_MATERIAL);   
  61.     glColor3f(r,g,b);      
  62.  
  63.     glutSolidTeapot(m);    
  64.  
  65.     glPopMatrix();         
  66.     glFlush();             
  67.  
  68.     glutSwapBuffers();         
  69. }
  70.  
  71. //-----------------------------------------------------------------------
  72. // keyboard callback function
  73. //  This is called whenever a keyboard key is hit.
  74. //-----------------------------------------------------------------------
  75.  
  76. void keyboard(unsigned char k, int x, int y)
  77. {
  78.     if(k=='r')
  79.     {
  80.        r=1;g=0;b=0;
  81.     }
  82.     glFlush();
  83.     glutPostRedisplay();
  84.  
  85.     if(k=='g')
  86.     {
  87.        r=0;g=1;b=0;
  88.     }
  89.     glFlush();
  90.     glutPostRedisplay();
  91.     if(k=='b')
  92.     {
  93.        r=0;g=0;b=1;
  94.     }
  95.     glFlush();
  96.     glutPostRedisplay();
  97.    
  98.     if(k=='l')
  99.     {
  100.        m++;
  101.     }
  102.     glFlush();
  103.     glutPostRedisplay();
  104.  
  105.     if(k=='s')
  106.     {
  107.        m--;
  108.     }
  109.     glFlush();
  110.     glutPostRedisplay();
  111.            
  112. }
  113.  
  114.  
  115. void usage()
  116. {
  117.     cout << "\n\
  118. -----------------------------------------------------------------------\n\
  119.  CMSC 427 Sample Program.\n\
  120.  Inputs:\n\
  121.    a:              Rotate counterclockwise\n\
  122.    l:              Rotate clockwise\n\
  123.    q:              Quit\n\
  124.  You may need to place the cursor over the graphics window for\n\
  125.  keyboard input to be processed.\n\
  126. -----------------------------------------------------------------------\n";
  127.     cout.flush();
  128. }
  129.  
  130.  
  131.  
  132. void processSpecialKeys(int key, int x, int y)
  133. {
  134.    
  135.     if(key==GLUT_KEY_UP)
  136.     {
  137.         glTranslatef(0,1,0);
  138.        
  139.     }
  140.     if(key==GLUT_KEY_DOWN && glutGetModifiers()==GLUT_ACTIVE_SHIFT)
  141.  
  142.     {
  143.         glTranslatef(0,-1,0);
  144.        
  145.     }
  146.  
  147.     if(key==GLUT_KEY_LEFT && glutGetModifiers()==GLUT_ACTIVE_SHIFT)
  148.     {
  149.         glTranslatef(-1,0,0);
  150.  
  151.     }
  152.     if(key==GLUT_KEY_RIGHT && glutGetModifiers()==GLUT_ACTIVE_CTRL)
  153.     {
  154.         glTranslatef(1,0,0);
  155.     }
  156.         glutPostRedisplay();
  157.  
  158.  
  159.    
  160. }
  161.  
  162.  
  163.  
  164. int main()
  165. {
  166.     usage();                // explain how to use
  167.     glutInitDisplayMode(        // initialize GLUT
  168.         GLUT_DOUBLE |       // use double buffering
  169.         GLUT_DEPTH |        // request memory for z-buffer
  170.         GLUT_RGB );     // set RGB color mode
  171.  
  172.     glutCreateWindow("GLUT Example");   // create the window
  173.  
  174.     glutDisplayFunc(display);       // call display() to redraw window
  175.     //glutKeyboardFunc(keyboard);       // call keyboard() when key is hit
  176.     glutSpecialFunc(processSpecialKeys);
  177.     init();             // our own initializations
  178.     glutMainLoop();         // let GLUT take care of everything
  179.     return 0;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement