MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / main

Function main

deps/SDL2/Xcode-iOS/Demos/src/accelerometer.c:157–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155
156
157int
158main(int argc, char *argv[])
159{
160
161 SDL_Window *window; /* main window */
162 SDL_Renderer *renderer;
163 int done; /* should we clean up and exit? */
164 int w, h;
165
166 /* initialize SDL */
167 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
168 fatalError("Could not initialize SDL");
169 }
170
171 /* create main window and renderer */
172 window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_ALLOW_HIGHDPI);
173 renderer = SDL_CreateRenderer(window, 0, 0);
174
175 SDL_GetWindowSize(window, &w, &h);
176 SDL_RenderSetLogicalSize(renderer, w, h);
177
178 /* print out some info about joysticks and try to open accelerometer for use */
179 printf("There are %d joysticks available\n", SDL_NumJoysticks());
180 printf("Default joystick (index 0) is %s\n", SDL_JoystickName(0));
181 accelerometer = SDL_JoystickOpen(0);
182 if (accelerometer == NULL) {
183 fatalError("Could not open joystick (accelerometer)");
184 }
185 printf("joystick number of axis = %d\n",
186 SDL_JoystickNumAxes(accelerometer));
187 printf("joystick number of hats = %d\n",
188 SDL_JoystickNumHats(accelerometer));
189 printf("joystick number of balls = %d\n",
190 SDL_JoystickNumBalls(accelerometer));
191 printf("joystick number of buttons = %d\n",
192 SDL_JoystickNumButtons(accelerometer));
193
194 /* load graphics */
195 initializeTextures(renderer);
196
197 /* setup ship */
198 shipData.x = (w - shipData.rect.w) / 2;
199 shipData.y = (h - shipData.rect.h) / 2;
200 shipData.vx = 0.0f;
201 shipData.vy = 0.0f;
202
203 done = 0;
204 /* enter main loop */
205 while (!done) {
206 double deltaTime = updateDeltaTime();
207 SDL_Event event;
208 while (SDL_PollEvent(&event)) {
209 if (event.type == SDL_QUIT) {
210 done = 1;
211 }
212 }
213 render(renderer, w, h, deltaTime);
214 SDL_Delay(1);

Callers

nothing calls this directly

Calls 15

SDL_InitFunction · 0.85
fatalErrorFunction · 0.85
SDL_CreateWindowFunction · 0.85
SDL_CreateRendererFunction · 0.85
SDL_GetWindowSizeFunction · 0.85
SDL_RenderSetLogicalSizeFunction · 0.85
SDL_NumJoysticksFunction · 0.85
SDL_JoystickNameFunction · 0.85
SDL_JoystickOpenFunction · 0.85
SDL_JoystickNumAxesFunction · 0.85
SDL_JoystickNumHatsFunction · 0.85
SDL_JoystickNumBallsFunction · 0.85

Tested by

no test coverage detected