#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#include <windows.h>
#include <GL/freeglut/freeglut.h>
#define WIDTH 320
#define HEIGHT 240
BYTE KeyTbl[256];
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void idle(void)
{
glClearColor(0.0, 0.0, 0.0, 1.0);
GetKeyboardState(KeyTbl);
if(KeyTbl[VK_RETURN] & 0x80)glClearColor(1.0, 1.0, 1.0, 1.0);
if(KeyTbl[VK_SPACE] & 0x80)glClearColor(1.0, 0.0, 0.0, 1.0);
if(KeyTbl[VK_LEFT] & 0x80)glClearColor(0.0, 1.0, 0.0, 1.0);
if(KeyTbl[VK_UP] & 0x80)glClearColor(0.0, 0.0, 1.0, 1.0);
if(KeyTbl[VK_RIGHT] & 0x80)glClearColor(1.0, 1.0, 0.0, 1.0);
if(KeyTbl[VK_DOWN] & 0x80)glClearColor(0.0, 1.0, 1.0, 1.0);
glutPostRedisplay();
}
void Init(){
glClearColor(0.3, 0.3, 0.3, 1.0);
glOrtho(0, WIDTH, HEIGHT, 0, -1, 1);
}
int main(int argc, char *argv[])
{
glutInitWindowPosition(100, 100);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow("キーボード");
glutDisplayFunc(display);
glutIdleFunc(idle);
Init();
glutMainLoop();
return 0;
}
|