switchbrew / switch-examples

Switch examples for devkitA64 and libnx.
https://devkitpro.org/viewforum.php?f=42
559 stars 99 forks source link

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

Closed SaiBalaji-PSS closed 3 years ago

SaiBalaji-PSS commented 3 years ago

Hello I'm new to switch Homebrew development. I'm starting with SDL2 for Switch Homebrew.I have downloaded and installed devkitt 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 some 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 Do I need to make changes to makefile? Here is my code

Code

`

include

include

include

include

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 initialization\n"<<SDL_GetError()<<"\n";
    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;
    }
}

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

BKa57

Stuck in emu

q7JNX

SaiBalaji-PSS commented 3 years ago

I was able to resolve it now it works fine