/* Copyright (c) 2012 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener adiener@sacredsoftware.net */ #include "glgraphics/GLIncludes.h" #include "shell/Shell.h" #include "shell/ShellBatteryInfo.h" #include "shell/ShellKeyCodes.h" #include "shell/Target.h" #if defined(STEM_PLATFORM_macosx) #include "nsopenglshell/NSOpenGLShell.h" #include "nsopenglshell/NSOpenGLTarget.h" #elif defined(STEM_PLATFORM_iphonesimulator) || defined(STEM_PLATFORM_iphoneos) #include "eaglshell/EAGLShell.h" #include "eaglshell/EAGLTarget.h" #else #include "glutshell/GLUTTarget.h" #endif #include void Target_init() { Shell_mainLoop(); } bool Target_draw() { printf("Target_draw()\n"); glClearColor(0.0f, 0.25f, 0.5f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); return true; } void Target_keyDown(unsigned int charCode, unsigned int keyCode, unsigned int modifierFlags) { printf("Target_keyDown(%d, %d, 0x%X)\n", charCode, keyCode, modifierFlags); if (keyCode == KEYBOARD_T) { printf("Shell_getCurrentTime(): %f\n", Shell_getCurrentTime()); } else if (keyCode == KEYBOARD_R) { printf("Shell_getResourcePath(): %s\n", Shell_getResourcePath()); } else if (keyCode == KEYBOARD_D) { Shell_redisplay(); } else if (keyCode == KEYBOARD_F) { printf("Shell_setFullScreen(true): %d\n", Shell_setFullScreen(true)); } else if (keyCode == KEYBOARD_W) { printf("Shell_setFullScreen(false): %d\n", Shell_setFullScreen(false)); } else if (keyCode == KEYBOARD_G) { printf("Shell_isFullScreen(): %d\n", Shell_isFullScreen()); } else if (keyCode == KEYBOARD_B) { printf("Shell_getBatteryState(): %d\n", Shell_getBatteryState()); printf("Shell_getBatteryLevel(): %f\n", Shell_getBatteryLevel()); } } void Target_keyUp(unsigned int keyCode, unsigned int modifierFlags) { printf("Target_keyUp(%d, 0x%X)\n", keyCode, modifierFlags); } void Target_keyModifiersChanged(unsigned int modifierFlags) { printf("Target_keyModifiersChanged(0x%X)\n", modifierFlags); } void Target_mouseDown(unsigned int buttonNumber, float x, float y) { printf("Target_mouseDown(%d, %f, %f)\n", buttonNumber, x, y); } void Target_mouseUp(unsigned int buttonNumber, float x, float y) { printf("Target_mouseUp(%d, %f, %f)\n", buttonNumber, x, y); } void Target_mouseMoved(float x, float y) { printf("Target_mouseMoved(%f, %f)\n", x, y); } void Target_mouseDragged(unsigned int buttonMask, float x, float y) { printf("Target_mouseDragged(0x%X, %f, %f)\n", buttonMask, x, y); } void Target_resized(unsigned int newWidth, unsigned int newHeight) { glViewport(0, 0, newWidth, newHeight); printf("Target_resized(%d, %d)\n", newWidth, newHeight); } void Target_backgrounded() { printf("Target_backgrounded()\n"); } void Target_foregrounded() { printf("Target_foregrounded()\n"); } #if defined(STEM_PLATFORM_macosx) void NSOpenGLTarget_configure(int argc, const char ** argv, struct NSOpenGLShellConfiguration * configuration) { int argIndex; printf("NSOpenGLTarget_configure(%d", argc); for (argIndex = 0; argIndex < argc; argIndex++) { printf(", \"%s\"", argv[argIndex]); } printf(", %p)\n", configuration); configuration->windowTitle = "Stem Application Template"; } #elif defined(STEM_PLATFORM_iphonesimulator) || defined(STEM_PLATFORM_iphoneos) void EAGLTarget_configure(int argc, char ** argv, struct EAGLShellConfiguration * configuration) { int argIndex; printf("EAGLTarget_configure(%d", argc); for (argIndex = 0; argIndex < argc; argIndex++) { printf(", \"%s\"", argv[argIndex]); } printf(", %p)\n", configuration); } void EAGLTarget_openURL(const char * url) { printf("EAGLTarget_openURL(\"%s\")\n", url); } void EAGLTarget_touchesCancelled(unsigned int buttonMask) { } void EAGLTarget_accelerometer(double x, double y, double z) { } #else void GLUTTarget_configure(int argc, const char ** argv, struct GLUTShellConfiguration * configuration) { int argIndex; printf("GLUTTarget_configure(%d", argc); for (argIndex = 0; argIndex < argc; argIndex++) { printf(", \"%s\"", argv[argIndex]); } printf(", %p)\n", configuration); configuration->windowTitle = "Stem Application Template"; } #endif