Hello everyone I'm new to switch Homebrew development. I'm starting with SDL2 for Switch Homebrew.I have downloaded and installed devout pro. And opened graphics sdl2-simple example c++ program and compiled it. It compiles successfully and generates a .nro file. Then I dropped it in Yuzu emulator it works fine as expected along with joy con inputs. But now I need to make that program much simpler so that when joy con A is pressed it should change the window background colour to red. I modified the example code by removing unnecessary methods(an user defined method which draws rectangle in particular pattern) as it is not needed for my code. Then I compiled it it compiles successfully and generates a .nro file.And also I used same Make file from original sdl2-simple example because I don't know how to create MakeFile. But when I drag and drop it in yuzu emulator it is stuck at launching progress bar. How to modify my code so that it changes window colour when joy con A is pressed. Here is my code.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
int main(int argc, char *argv[])
{
SDL_Event event;
SDL_Window *window;
SDL_Renderer *renderer;
int done = 0;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
SDL_Log("SDL_Init: %s\n", SDL_GetError());
return -1;
}
window = SDL_CreateWindow("sdl2_gles2", 0, 0, 1920, 1080, 0);
if (!window) {
SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError());
SDL_Quit();
return -1;
}
// create a renderer (OpenGL ES2)
renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer) {
SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError());
SDL_Quit();
return -1;
}
for (int i = 0; i < 2; i++) {
if (SDL_JoystickOpen(i) == NULL) {
SDL_Log("SDL_JoystickOpen: %s\n", SDL_GetError());
SDL_Quit();
return -1;
}
}
while (!done) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_JOYBUTTONDOWN:
{
SDL_Log("Joystick %d button %d down\n",
event.jbutton.which, event.jbutton.button);
if (event.jbutton.which == 0) {
if (event.jbutton.button == 0) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
done = 1;
}
}
break;
}
default:
{
break;
}
}
}
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}