mirror of
https://github.com/ysoftdevs/cpp-examples.git
synced 2026-01-11 14:30:32 +01:00
add SDL2 samples
This commit is contained in:
14
README.md
14
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
|
||||
----
|
||||
|
||||
|
||||
97
sdl/01-sdl2-init/01-sdl2-init.vcxproj
Normal file
97
sdl/01-sdl2-init/01-sdl2-init.vcxproj
Normal file
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{C8D4C9F2-D4C8-48EE-8F48-0A56BBBA2ECA}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>sdl2sample</RootNamespace>
|
||||
<ProjectName>01-sdl2-init</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<ExecutablePath>$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\SDL2-2.0.1\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\SDL2-2.0.1\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>SDL2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="01-sdl2-init.cpp" />
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
51
sdl/02-sdl2-video/02-sdl2-video.cpp
Normal file
51
sdl/02-sdl2-video/02-sdl2-video.cpp
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
BIN
sdl/02-sdl2-video/smajlik.bmp
Normal file
BIN
sdl/02-sdl2-video/smajlik.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
14
sdl/DownloadLibrary.ps1
Normal file
14
sdl/DownloadLibrary.ps1
Normal file
@@ -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")
|
||||
7
sdl/README.md
Normal file
7
sdl/README.md
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user