Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GLUT_LEFT_BUTTON0
- #define GLUT_MIDDLE_BUTTON1
- #define GLUT_RIGHT_BUTTON2
- #define GLUT_DOWN0
- #define GLUT_UP1
- #include <stdio.h>
- #include <stdlib.h>
- #include <GLUT/glut.h>
- float shiftX,shiftY;
- float mouseX,mouseY;
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glTranslatef(shiftX,shiftY,0);
- glColor3d(0.0, 0.0, 0.0);//色
- glBegin(GL_LINE_LOOP);
- glVertex2d(-0.1f, -0.1f);//位置
- glVertex2d(0.1f, -0.1f);//位置
- glVertex2d(0.1f, 0.1f);//位置
- glVertex2d(-0.1f, 0.1f);//位置
- glEnd();
- glFlush();
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key) {
- case 'q':
- case 'Q':
- case '\033': /* '\033' は ESC の ASCII コード */
- exit(0);
- default:
- break;
- }
- }
- void resize(int w, int h)
- {
- }
- void mouse(int btn, int state, int x, int y){
- if(state == GLUT_DOWN){
- mouseX = x;
- mouseY = y;
- }
- else if(btn==GLUT_MIDDLE_BUTTON){
- shiftX += 0.01f*(x - mouseX);
- shiftY -= 0.01f*(y - mouseY);
- display();
- }
- }
- void init(void)
- {
- glClearColor(1.0, 1.0, 1.0, 0.0);
- }
- int main(int argc, char *argv[])
- {
- glutInitWindowPosition(100, 100);//ウィンドウの位置
- glutInitWindowSize(600, 600);//ウィンドウの幅と大きさ
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGBA);
- glutCreateWindow(argv[0]);
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutMouseFunc(mouse);
- //motionfunc
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement