00001 /* 00002 RenderStack Support library for OpenGL 3+ 00003 Copyright (C) 2010 Timo Suoranta 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00027 #ifndef RS_H 00028 #define RS_H 00029 00030 #include "renderstack/rs_platform.h" 00031 00032 #if defined(NDEBUG) 00033 #define RS_ASSERT(x) 00034 #else 00035 #define RS_ASSERT(_expression) if(!(_expression)){rs_application_fail("ASSERTION FAILED:" #_expression "\n file:" __FILE__ "\n");} 00036 #endif 00037 00038 #if defined(__cplusplus) 00039 # define RS_BEGIN_EXTERN_C extern "C" { 00040 # define RS_END_EXTERN_C } 00041 #else 00042 # define RS_BEGIN_EXTERN_C 00043 # define RS_END_EXTERN_C 00044 #endif 00045 00046 #define RS_PI 3.14159265358979323846f 00047 #define RS_TWO_PI (2.0f * RS_PI) 00048 #define RS_HALF_PI (0.5f * RS_PI) 00049 #define RS_EPSILON (0.00001f) 00050 00051 #define RS_NO_ERROR 0x1000 00052 #define RS_INVALID_ENUM 0x1001 00053 #define RS_INVALID_VALUE 0x1002 00054 #define RS_INVALID_OPERATION 0x1003 00055 #define RS_OUT_OF_MEMORY 0x1004 00056 #define RS_NAME_LENGTH 128 00057 #define RS_MIN(a,b) ((a)<(b)?(a):(b)) 00058 #define RS_MAX(a,b) ((a)>(b)?(a):(b)) 00059 #define RS_NEAR_ZERO(x) (fabsf(x) <= RS_EPSILON) 00060 #define RS_TOLERANCE(x,y) (fabsf(x - y) <= RS_EPSILON * RS_MAX(1.0f, RS_MAX(fabsf(x), fabsf(y)))) 00061 00062 #define RS_GAMEPAD_DPAD_UP 0x0001 00063 #define RS_GAMEPAD_DPAD_DOWN 0x0002 00064 #define RS_GAMEPAD_DPAD_LEFT 0x0004 00065 #define RS_GAMEPAD_DPAD_RIGHT 0x0008 00066 #define RS_GAMEPAD_START 0x0010 00067 #define RS_GAMEPAD_BACK 0x0020 00068 #define RS_GAMEPAD_LEFT_THUMB 0x0040 00069 #define RS_GAMEPAD_RIGHT_THUMB 0x0080 00070 #define RS_GAMEPAD_LEFT_SHOULDER 0x0100 00071 #define RS_GAMEPAD_RIGHT_SHOULDER 0x0200 00072 #define RS_GAMEPAD_A 0x1000 00073 #define RS_GAMEPAD_B 0x2000 00074 #define RS_GAMEPAD_X 0x4000 00075 #define RS_GAMEPAD_Y 0x8000 00076 00077 struct rs_pointer 00078 { 00079 int x; 00080 int y; 00081 int buttons[3]; 00082 int dx; 00083 int dy; 00084 }; 00085 00086 struct rs_controller 00087 { 00088 int state; 00089 int buttons; 00090 unsigned char left_trigger; 00091 unsigned char right_trigger; 00092 short lx; 00093 short ly; 00094 short rx; 00095 short ry; 00096 }; 00097 00098 struct rs_context 00099 { 00100 int run; 00101 struct rs_pointer pointer; 00102 struct rs_controller controllers[4]; 00103 int keyboard[256]; 00104 int need_reshape; 00105 int focus; 00106 00107 struct rs_platform_context platform; 00108 }; 00109 00110 RS_BEGIN_EXTERN_C 00111 00112 int rs_application_begin (void); 00113 void rs_application_end (char *message); 00114 void rs_application_update (void); 00115 void rs_application_reshape (void); 00116 void rs_application_fail (char *message); 00117 00118 struct rs_context* rs_context (void); 00119 struct rs_pointer* rs_pointer (void); 00120 00121 RS_END_EXTERN_C 00122 00123 #endif 00124