Skip to content

Commit

Permalink
Add SDL sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bendmorris committed Mar 23, 2019
1 parent 6f2993b commit 8c2078b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/README.md
@@ -1,3 +1,3 @@
To build and run any of the samples:

kitc -s samples SAMPLE_NAME --run
kitc --run path/to/sample
File renamed without changes.
25 changes: 25 additions & 0 deletions samples/sdl/sdl.kit
@@ -0,0 +1,25 @@
include "SDL2/SDL.h" => "SDL2";
include "stdio.h";

function main() {
var window: Ptr[SDL_Window] = null;
var screenSurface: Ptr[SDL_Surface] = null;
if SDL_Init(SDL_INIT_VIDEO) < 0 {
panic("could not initialize sdl2: %s\n", SDL_GetError());
}
window = SDL_CreateWindow(
"Hello from Kit and SDL2",
${SDL_WINDOWPOS_UNDEFINED: Int}, ${SDL_WINDOWPOS_UNDEFINED: Int},
640, 480,
SDL_WINDOW_SHOWN as Uint
);
if window == null {
panic("could not create window: %s\n", SDL_GetError());
}
screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, null, SDL_MapRGB(screenSurface.format, 0x80, 0xff, 0xe6));
SDL_UpdateWindowSurface(window);
SDL_Delay(2000);
SDL_DestroyWindow(window);
SDL_Quit();
}

0 comments on commit 8c2078b

Please sign in to comment.