Advertisement
Kojima0502

Square_move

Jan 25th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <GLUT/glut.h>
  4.  
  5. void display(void)
  6. {
  7.    
  8.     glClear(GL_COLOR_BUFFER_BIT);
  9.     glColor3d(0.0, 0.0, 0.0);//色
  10.     glBegin(GL_LINE_LOOP);
  11.     glVertex2d(-0.1, -0.1);//位置
  12.     glVertex2d(0.1, -0.1);//位置
  13.     glVertex2d(0.1, 0.1);//位置
  14.     glVertex2d(-0.1, 0.1);//位置
  15.     glEnd();
  16.     glFlush();
  17.    
  18. }
  19.  
  20. void keyboard(unsigned char key, int x, int y)
  21. {
  22.     switch (key) {
  23.         case 'q':
  24.         case 'Q':
  25.         case '\033':  /* '\033' は ESC の ASCII コード */
  26.             exit(0);
  27.         default:
  28.             break;
  29.     }
  30. }
  31.  
  32. void resize(int w, int h)
  33. {
  34.    
  35. }
  36.  
  37. void mouse(int button, int state, int x, int y)
  38. {
  39.     switch (button) {
  40.         case GLUT_LEFT_BUTTON:
  41.            
  42.                 glEnd();
  43.                 glFlush();
  44.                
  45.                     }
  46. }
  47.  
  48. void motion(int x, int y)
  49. {
  50.     glEnable(GL_COLOR_LOGIC_OP);
  51.     glLogicOp(GL_INVERT);
  52.    
  53.     glBegin(GL_LINES);
  54.     glVertex2i(x, y);
  55.     glEnd();
  56.    
  57.     glFlush();
  58.    }
  59.  
  60.  
  61. void init(void)
  62.  
  63.     {
  64.         glClearColor(1.0, 1.0, 1.0, 0.0);
  65.    
  66. }
  67.  
  68. int main(int argc, char *argv[])
  69. {
  70.     glutInitWindowPosition(100, 100);//ウィンドウの位置
  71.     glutInitWindowSize(600, 600);//ウィンドウの幅と大きさ
  72.     glutInit(&argc, argv);
  73.     glutInitDisplayMode(GLUT_RGBA);
  74.     glutCreateWindow(argv[0]);
  75.     glutDisplayFunc(display);
  76.     glutKeyboardFunc(keyboard);
  77.  
  78.     init();
  79.     glutMainLoop();
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement