#include <gl/glut.h>
float X = 0;
float Y = 0;
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glVertex2d(X-0.1,Y-0.1);
glVertex2d(X-0.1,Y+0.1);
glVertex2d(X+0.1,Y+0.1);
glVertex2d(X+0.1,Y-0.1);
if (X == 1.0 || X == -1.0) {//虚像
glVertex2d(-X - 0.1, Y - 0.1);
glVertex2d(-X - 0.1, Y + 0.1);
glVertex2d(-X + 0.1, Y + 0.1);
glVertex2d(-X + 0.1, Y - 0.1);
}
if (Y == 1.0 || Y == -1.0) {//虚像
glVertex2d(X - 0.1,-Y - 0.1);
glVertex2d(X - 0.1,-Y + 0.1);
glVertex2d(X + 0.1,-Y + 0.1);
glVertex2d(X + 0.1,-Y - 0.1);
}
glEnd();
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'a':
case 127:
X -= 0.2;
break;
case 'w':
case 27:
Y += 0.2;
break;
case 's':
case' ':
X += 0.2;
break;
case 'z':
case 'E':
Y -= 0.2;
break;
default:
break;
}
//入力補正
if (X > 1.1) X = -1;
if (X < -1.1) X = 1;
if (Y > 1.1) Y = -1;
if (Y < -1.1) Y = 1;
//強制再描画
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(640, 480);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glClearColor(0.0, 0.0, 1.0, 0.0);
glutMainLoop();
return 0;
}
I2luY2x1ZGUgPGdsL2dsdXQuaD4KCmZsb2F0IFggPSAwOwpmbG9hdCBZID0gMDsKCnZvaWQgZGlzcGxheSh2b2lkKSB7CgoJZ2xDbGVhcihHTF9DT0xPUl9CVUZGRVJfQklUKTsKCglnbEJlZ2luKEdMX1FVQURTKTsKCWdsVmVydGV4MmQoWC0wLjEsWS0wLjEpOwoJZ2xWZXJ0ZXgyZChYLTAuMSxZKzAuMSk7CglnbFZlcnR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