diff --git a/README.md b/README.md index 4225f74..aa3451c 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,20 @@ How to run (PowerShell + VS 2013): restore C++ REST SDK CTRL+F5 to run the project +Simple DirectMedia Layer 2 +-------------------------- + +SDL2 is multiplatform library suitable for developing applications like games. +Example is based on SDL2. +You can download version for Visual Studio at: http://libsdl.org/release/SDL2-devel-2.0.1-VC.zip +This library is also available in all common Linux ditributions. + +How to run (PowerShell + VS 2013): + + cd sdl + .\DownloadLibrary.ps1 + ii .\sdl2-sample.sln + node ---- diff --git a/sdl/01-sdl2-init/01-sdl2-init.vcxproj b/sdl/01-sdl2-init/01-sdl2-init.vcxproj new file mode 100644 index 0000000..c91e5b0 --- /dev/null +++ b/sdl/01-sdl2-init/01-sdl2-init.vcxproj @@ -0,0 +1,97 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {C8D4C9F2-D4C8-48EE-8F48-0A56BBBA2ECA} + Win32Proj + sdl2sample + 01-sdl2-init + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + $(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH); + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + ..\SDL2-2.0.1\include;%(AdditionalIncludeDirectories) + + + Console + true + ..\SDL2-2.0.1\lib\x86;%(AdditionalLibraryDirectories) + SDL2.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdl/02-sdl2-video/02-sdl2-video.cpp b/sdl/02-sdl2-video/02-sdl2-video.cpp new file mode 100644 index 0000000..cc9a39b --- /dev/null +++ b/sdl/02-sdl2-video/02-sdl2-video.cpp @@ -0,0 +1,51 @@ +// 02-sdl2-video.cpp : SDL2 example - initialize video and display image +// + +#include "stdafx.h" +#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/smajlik.bmp b/sdl/02-sdl2-video/smajlik.bmp new file mode 100644 index 0000000..141a058 Binary files /dev/null and b/sdl/02-sdl2-video/smajlik.bmp differ diff --git a/sdl/DownloadLibrary.ps1 b/sdl/DownloadLibrary.ps1 new file mode 100644 index 0000000..6f7d044 --- /dev/null +++ b/sdl/DownloadLibrary.ps1 @@ -0,0 +1,14 @@ +Write-Host("Downloading library") +$workingPath = (Get-Location).path +$clnt = new-object System.Net.WebClient +$url = "http://libsdl.org/release/SDL2-devel-2.0.1-VC.zip" +$file = $workingPath + "\SDL2-devel-2.0.1-VC.zip" +$clnt.DownloadFile($url,$file) + +Write-Host("Unzip the file to local directory") +$shell_app=new-object -com shell.application +$zip_file = $shell_app.namespace($file) +$destination = $shell_app.namespace($workingPath) +$destination.Copyhere($zip_file.items()) + +Write-Host("Done") diff --git a/sdl/README.md b/sdl/README.md new file mode 100644 index 0000000..d45751a --- /dev/null +++ b/sdl/README.md @@ -0,0 +1,7 @@ +Dependencies +------------ + +Download and unzip dependency http://libsdl.org/release/SDL2-devel-2.0.1-VC.zip +to this directory. You should see directory SDL2-2.0.1 with SDL2 files. + +Alternatively you can download library by DownloadLibrary.ps1 script.