Initial commit
This commit is contained in:
82
src/main.cpp
Normal file
82
src/main.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#include <switch.h>
|
||||
|
||||
extern "C" void userAppInit() {
|
||||
socketInitializeDefault();
|
||||
nxlinkStdio();
|
||||
appletSetWirelessPriorityMode(AppletWirelessPriorityMode_OptimizedForWlan);
|
||||
plInitialize(PlServiceType_User);
|
||||
}
|
||||
|
||||
extern "C" void userAppExit() {
|
||||
plExit();
|
||||
socketExit();
|
||||
}
|
||||
#endif
|
||||
|
||||
// some switch buttons
|
||||
#define JOY_A 0
|
||||
#define JOY_B 1
|
||||
#define JOY_X 2
|
||||
#define JOY_Y 3
|
||||
#define JOY_PLUS 10
|
||||
#define JOY_MINUS 11
|
||||
#define JOY_LEFT 12
|
||||
#define JOY_UP 13
|
||||
#define JOY_RIGHT 14
|
||||
#define JOY_DOWN 15
|
||||
|
||||
static void die(const char* msg) {
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Main code
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) die("pass a single media file as argument");
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) die("SDL init failed");
|
||||
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
SDL_JoystickOpen(0);
|
||||
|
||||
SDL_Window* window = SDL_CreateWindow(argv[1], 0, 0, 1280, 720, 0);
|
||||
if (!window) die("failed to create SDL window");
|
||||
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
SDL_GL_MakeCurrent(window, context);
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
goto done;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
switch (event.jbutton.button) {
|
||||
case JOY_PLUS:
|
||||
goto done;
|
||||
}
|
||||
SDL_Log("Joystick %d button %d down\n", event.jbutton.which, event.jbutton.button);
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
done:
|
||||
SDL_GL_DeleteContext(context);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user