Example #1
0
//Called whenever a key on the keyboard was pressed.
//The key is given by the ''key'' parameter, which is in ASCII.
//It's often a good idea to have the escape key (ASCII value 27) call glutLeaveMainLoop() to
//exit the program.
void keyboard(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 27:
		delete g_pScene;
		g_pScene = NULL;
		glutLeaveMainLoop();
		return;
	case 32:
		g_lightPole.Reset();
		break;
	case 't':
		g_bDrawCameraPos = !g_bDrawCameraPos;
		break;
	case 'g':
		g_bShowOtherLights = !g_bShowOtherLights;
		break;
	case 'p':
		g_timer.TogglePause();
		break;
	case '\r': //Enter key.
		{
			try
			{
				LoadAndSetupScene();
			}
			catch(std::exception &except)
			{
				printf("Failed to reload, due to: %s\n", except.what());
				return;
			}
		}
		break;
	}

	{
		int possibleIndex = (int)key - (int)'1';
		if((0 <= possibleIndex) && (possibleIndex < NUM_LIGHT_TEXTURES))
		{
			g_currTextureIndex = key - '1';
			printf("%s\n", g_texDefs[g_currTextureIndex].name);
		}
	}

	g_viewPole.CharPress(key);
	g_lightPole.CharPress(key);
}