X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fmain.cc;h=d24428cc65e9362b8820a5f525a60ad5da0f0ed0;hp=fb8a2e20c3798e68aef7a471102755d3eb73f1cb;hb=8b3ce77b133bbac9979e75a6c88f6b86559d2705;hpb=3aacec4aee795e703e8eb9d6852ca47a3be065ee diff --git a/src/main.cc b/src/main.cc index fb8a2e2..d24428c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,11 +17,13 @@ static bool quit; static unsigned int start_time; static unsigned int modkeys; +SDL_GameController *gamepad; + static int scale_factor = 1; int main(int argc, char **argv) { - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { fprintf(stderr, "failed to initialize SDL\n"); return 1; } @@ -46,6 +48,7 @@ int main(int argc, char **argv) int val; SDL_GL_GetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, &val); printf("SDL says we %s an sRGB framebuffer\n", val ? "got" : "didn't get"); + fb_srgb = val; if(!(ctx = SDL_GL_CreateContext(win))) { fprintf(stderr, "failed to create OpenGL context\n"); @@ -55,6 +58,17 @@ int main(int argc, char **argv) SDL_GL_GetDrawableSize(win, &win_width, &win_height); win_aspect = (float)win_width / (float)win_height; + printf("detected %d joysticks\n", SDL_NumJoysticks()); + for(int i=0; imotion.xrel * 0.5, ev->motion.yrel * 0.5); + app_mouse_delta(ev->motion.xrel, ev->motion.yrel); } else { app_mouse_motion(ev->motion.x * scale_factor, ev->motion.y * scale_factor); } break; case SDL_WINDOWEVENT: - if(ev->window.event == SDL_WINDOWEVENT_RESIZED) { + if(ev->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { SDL_GL_GetDrawableSize(win, &win_width, &win_height); win_aspect = (float)win_width / (float)win_height; scale_factor = win_width / ev->window.data1; app_reshape(win_width, win_height); } break; + + case SDL_CONTROLLERAXISMOTION: + app_gamepad_axis(ev->caxis.axis, ev->caxis.value / 32768.0f); + break; + + case SDL_CONTROLLERBUTTONDOWN: + case SDL_CONTROLLERBUTTONUP: + app_gamepad_button(ev->cbutton.button, ev->type == SDL_CONTROLLERBUTTONDOWN); + break; } }