-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
cmake-build-debug | ||
.idea | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cmake_minimum_required(VERSION 3.0.0) | ||
project(sdl2_config_example VERSION 0.1.0) | ||
|
||
include_directories(/usr/local/include) | ||
|
||
execute_process( | ||
COMMAND sdl2-config --static-libs | ||
OUTPUT_VARIABLE sdl2_static_libs_output | ||
) | ||
|
||
separate_arguments(sdl2_static_libs NATIVE_COMMAND ${sdl2_static_libs_output}) | ||
|
||
|
||
add_executable(sdl2_config_example main.c) | ||
|
||
target_link_options(sdl2_config_example PRIVATE ${sdl2_static_libs}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <SDL2/SDL.h> | ||
|
||
#define WIDTH 550 | ||
#define HEIGHT 400 | ||
|
||
void draw(SDL_Renderer *renderer) { | ||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); | ||
SDL_Rect rect = {0, 0, 100, 100}; | ||
SDL_RenderFillRect(renderer, &rect); | ||
} | ||
|
||
int main() { | ||
SDL_Window *win; | ||
SDL_Renderer *renderer; | ||
if (SDL_Init(SDL_INIT_VIDEO)) { | ||
SDL_Log("Unable to init SLD: %s", SDL_GetError()); | ||
return 1; | ||
} | ||
win = SDL_CreateWindow( | ||
"Hello World", | ||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, | ||
WIDTH, HEIGHT, | ||
SDL_WINDOW_OPENGL | ||
); | ||
if (win == NULL) { | ||
SDL_Log("Unable to create window: %s", SDL_GetError()); | ||
return 1; | ||
} | ||
|
||
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); | ||
if (renderer == NULL) { | ||
SDL_Log("Can not create renderer: %s", SDL_GetError()); | ||
return 1; | ||
} | ||
|
||
while (1) { | ||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); | ||
SDL_RenderClear(renderer); | ||
draw(renderer); | ||
SDL_RenderPresent(renderer); | ||
|
||
SDL_Event event; | ||
if (SDL_PollEvent(&event)) { | ||
if (event.type == SDL_QUIT) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
SDL_DestroyRenderer(renderer); | ||
SDL_DestroyWindow(win); | ||
SDL_Quit(); | ||
return 0; | ||
} |