simple SDL2 c++ program in Switch using devkit pro not booting in emulator

  c++, devkitpro, homebrew, sdl, sdl-2

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 it changes the background colour of the SDL window when launched in emulator. 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 it is launched.
The code is simpler when launched it should set the window color to white. Here is my code.It compiles success fully and generates .nro file. But when I drop it in Yuzu it is stuck at launching progress bar screen. I don’t know where I’m going wrong

#include <stdlib.h>
#include <stdio.h>
#include<iostream>
#include <SDL.h>
#include<SDL2/SDL.h>

int main(int argc, char *argv[])
{
   
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window* Window = NULL;

    Window = SDL_CreateWindow("demo",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,800,450,SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);

    if(Window == NULL)
    {
        std::cout<<"Error in window initializationn"<<SDL_GetError()<<"n";
        return -1;
    }

    for (int i = 0; i < 2; i++) {
        if (SDL_JoystickOpen(i) == NULL) {
            SDL_Log("SDL_JoystickOpen: %sn", SDL_GetError());
            SDL_Quit();
            return -1;
        }
    }
 
   SDL_Surface* Screen = SDL_GetWindowSurface(Window);
   
    bool running = true;
    SDL_Event event;
   Uint32 white = SDL_MapRGB(Screen->format,255,255,255);
   
   SDL_FillRect(Screen,NULL,white);

   SDL_UpdateWindowSurface(Window);

    while (running)
    {
        while (SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                running = false;
                break;
            }
       
        }
    }
   
    SDL_DestroyWindow(Window);
    SDL_Quit();

    return 0;
}

Compilation

Stuck in emulator

Source: Windows Questions C++

LEAVE A COMMENT