diff --git a/README.md b/README.md index 68949d9..151d200 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ It is possible to generate project for Visual Studio: Compiled binary will be stored in: - build\binaries\mainExecutable + build/binaries/mainExecutable node ---- diff --git a/sdl/01-sdl2-init/build.gradle b/sdl/01-sdl2-init/build.gradle index dcc79c3..2eb8f75 100644 --- a/sdl/01-sdl2-init/build.gradle +++ b/sdl/01-sdl2-init/build.gradle @@ -21,7 +21,6 @@ executables { if (toolChain in VisualCpp) { cCompiler.args "/MD" linker.args "/SUBSYSTEM:CONSOLE", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2main.lib", "SDL2.lib" - //linker.args "/SUBSYSTEM:WINDOWS", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2.lib" } } } diff --git a/sdl/02-sdl2-video/02-sdl2-video.cpp b/sdl/02-sdl2-video/02-sdl2-video.cpp deleted file mode 100644 index e7e0f45..0000000 --- a/sdl/02-sdl2-video/02-sdl2-video.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// 02-sdl2-video.cpp : SDL2 example - initialize video and display image -// - -#include -#include -#include "SDL.h" - -int _tmain(int argc, _TCHAR* argv[]) { - if (SDL_Init(SDL_INIT_EVERYTHING) == -1){ - printf("Error initializing SDL: %s\n", SDL_GetError()); - return 1; - } - - SDL_Window *win = nullptr; - win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN); - if (win == nullptr){ - printf("%i\n", SDL_GetError()); - return 1; - } - - SDL_Renderer *ren = nullptr; - ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); - if (ren == nullptr){ - printf("%i\n", SDL_GetError()); - return 1; - } - - SDL_Surface *bmp = nullptr; - bmp = SDL_LoadBMP("smajlik.bmp"); - if (bmp == nullptr){ - printf("%i\n", SDL_GetError()); - return 1; - } - - SDL_Texture *tex = nullptr; - tex = SDL_CreateTextureFromSurface(ren, bmp); - SDL_FreeSurface(bmp); - - SDL_RenderClear(ren); - SDL_RenderCopy(ren, tex, NULL, NULL); - SDL_RenderPresent(ren); - - SDL_Delay(2000); - - SDL_DestroyTexture(tex); - SDL_DestroyRenderer(ren); - SDL_DestroyWindow(win); - - SDL_Quit(); - return 0; -} - diff --git a/sdl/02-sdl2-video/build.gradle b/sdl/02-sdl2-video/build.gradle new file mode 100644 index 0000000..2eb8f75 --- /dev/null +++ b/sdl/02-sdl2-video/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'c' +apply plugin: 'visual-studio' + +sources { + main { + c { + source { + // Include just source, avoid including *.swp and other helper files + include "**/*.c" + } + exportedHeaders { + srcDir "../build/SDL2-2.0.3/include" + } + } + } +} + +executables { + main { + binaries.all { + if (toolChain in VisualCpp) { + cCompiler.args "/MD" + linker.args "/SUBSYSTEM:CONSOLE", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2main.lib", "SDL2.lib" + } + } + } +} + diff --git a/sdl/02-sdl2-video/src/main/c/sdl2-video.c b/sdl/02-sdl2-video/src/main/c/sdl2-video.c new file mode 100644 index 0000000..ea60c90 --- /dev/null +++ b/sdl/02-sdl2-video/src/main/c/sdl2-video.c @@ -0,0 +1,52 @@ +// 02-sdl2-video.cpp : SDL2 example - initialize video and display image +// + +#include +#include "SDL.h" + +int main(int argc, char* argv[]) { + SDL_Window *win = NULL; + SDL_Renderer *ren = NULL; + SDL_Surface *bmp = NULL; + SDL_Texture *tex = NULL; + + if (SDL_Init(SDL_INIT_EVERYTHING) == -1){ + printf("Error initializing SDL: %s\n", SDL_GetError()); + return 1; + } + + win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN); + if (win == NULL){ + printf("%s\n", SDL_GetError()); + return 2; + } + + ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (ren == NULL){ + printf("%s\n", SDL_GetError()); + return 3; + } + + bmp = SDL_LoadBMP("./smajlik.bmp"); + if (bmp == NULL){ + printf("%s\n", SDL_GetError()); + return 4; + } + + tex = SDL_CreateTextureFromSurface(ren, bmp); + SDL_FreeSurface(bmp); + + SDL_RenderClear(ren); + SDL_RenderCopy(ren, tex, NULL, NULL); + SDL_RenderPresent(ren); + + SDL_Delay(2000); + + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + + SDL_Quit(); + return 0; +} +