I am trying to setup sdl2 on my mac and all headers get detected in my test code. When I compile and run the code it should open a fully red window but the only thing that I get is a pop up on my task bar that I can't click on. I had similar problems with pygame and I assume it's due to the fact I try it on an M1 chip.
Cmake File:
cmake_minimum_required(VERSION 3.23)
project(SDLTest)
set(CMAKE_CXX_STANDARD 23)
add_executable(SDLTest main.cpp)
set(SDL2_INCLUDE_DIRS /opt/homebrew/Cellar/sdl2/2.26.4/include)
set(SDL2_LIBRARIES /opt/homebrew/Cellar/sdl2/2.26.4/lib/libSDL2.dylib)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
Code:
int main( int argc, char * args [] )
{
SDL_Window * window;
SDL_Renderer * renderer;
SDL_Init( SDL_INIT_EVERYTHING );
// Check for successful initialization
if( SDL_Init( SDL_INIT_EVERYTHING ) != 0 )
{
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return -1;
}
// Create window and renderer using the Metal backend
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
SDL_CreateWindowAndRenderer( 640, 480, SDL_WINDOW_RESIZABLE, &window, &renderer );
// Set the render draw color
SDL_SetRenderDrawColor( renderer, 255, 0, 0, 255 );
// Clear the screen with the render draw color
SDL_RenderClear( renderer );
// Update the screen with any changes made to the renderer
SDL_RenderPresent( renderer );
// Wait for 3 seconds before exiting
SDL_Delay( 3000 );
// Clean up SDL
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}