Skip to content

Commit b513b55

Browse files
committed
Stub sdl2 project for windows
0 parents  commit b513b55

File tree

5 files changed

+242
-0
lines changed

5 files changed

+242
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
msvc-project/Release
2+
msvc-project/Debug
3+
msvc-project/sdl2stub/Release
4+
msvc-project/sdl2stub/Debug
5+
*.vcxproj.filters
6+
.vs

msvc-project/sdl2stub.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.852
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdl2stub", "sdl2stub\sdl2stub.vcxproj", "{417EC439-D1EA-4943-8F55-DCF65BDE171E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Debug|x64.ActiveCfg = Debug|x64
17+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Debug|x64.Build.0 = Debug|x64
18+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Debug|x86.ActiveCfg = Debug|Win32
19+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Debug|x86.Build.0 = Debug|Win32
20+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Release|x64.ActiveCfg = Release|x64
21+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Release|x64.Build.0 = Release|x64
22+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Release|x86.ActiveCfg = Release|Win32
23+
{417EC439-D1EA-4943-8F55-DCF65BDE171E}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {5F255BF5-24E8-4434-AF70-FED1B0153122}
30+
EndGlobalSection
31+
EndGlobal
+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>15.0</VCProjectVersion>
23+
<ProjectGuid>{417EC439-D1EA-4943-8F55-DCF65BDE171E}</ProjectGuid>
24+
<RootNamespace>sdl2stub</RootNamespace>
25+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v141</PlatformToolset>
32+
<CharacterSet>MultiByte</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v141</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>MultiByte</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v141</PlatformToolset>
45+
<CharacterSet>MultiByte</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v141</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>MultiByte</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
73+
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(VCPKG_ROOT)\installed\x86-windows\include\SDL2</IncludePath>
74+
</PropertyGroup>
75+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
76+
<ClCompile>
77+
<WarningLevel>Level3</WarningLevel>
78+
<Optimization>Disabled</Optimization>
79+
<SDLCheck>true</SDLCheck>
80+
<ConformanceMode>true</ConformanceMode>
81+
</ClCompile>
82+
</ItemDefinitionGroup>
83+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
84+
<ClCompile>
85+
<WarningLevel>Level3</WarningLevel>
86+
<Optimization>Disabled</Optimization>
87+
<SDLCheck>true</SDLCheck>
88+
<ConformanceMode>true</ConformanceMode>
89+
</ClCompile>
90+
</ItemDefinitionGroup>
91+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
92+
<ClCompile>
93+
<WarningLevel>Level3</WarningLevel>
94+
<Optimization>MaxSpeed</Optimization>
95+
<FunctionLevelLinking>true</FunctionLevelLinking>
96+
<IntrinsicFunctions>true</IntrinsicFunctions>
97+
<SDLCheck>true</SDLCheck>
98+
<ConformanceMode>true</ConformanceMode>
99+
<AdditionalIncludeDirectories>$(VCPKG_ROOT)\installed\x86-windows\include</AdditionalIncludeDirectories>
100+
</ClCompile>
101+
<Link>
102+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
103+
<OptimizeReferences>true</OptimizeReferences>
104+
<AdditionalLibraryDirectories>$(VCPKG_ROOT)\installed\x86-windows\lib;$(VCPKG_ROOT)\installed\x86-windows\lib\manual-link</AdditionalLibraryDirectories>
105+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);SDL2.lib;SDL2Main.lib;opengl32.lib</AdditionalDependencies>
106+
<SubSystem>Windows</SubSystem>
107+
</Link>
108+
</ItemDefinitionGroup>
109+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
110+
<ClCompile>
111+
<WarningLevel>Level3</WarningLevel>
112+
<Optimization>MaxSpeed</Optimization>
113+
<FunctionLevelLinking>true</FunctionLevelLinking>
114+
<IntrinsicFunctions>true</IntrinsicFunctions>
115+
<SDLCheck>true</SDLCheck>
116+
<ConformanceMode>true</ConformanceMode>
117+
</ClCompile>
118+
<Link>
119+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
120+
<OptimizeReferences>true</OptimizeReferences>
121+
</Link>
122+
</ItemDefinitionGroup>
123+
<ItemGroup>
124+
<ClCompile Include="..\..\src\main.cpp" />
125+
</ItemGroup>
126+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
127+
<ImportGroup Label="ExtensionTargets">
128+
</ImportGroup>
129+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

src/main.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//SDL2 flashing random color example
2+
//Should work on iOS/Android/Mac/Windows/Linux
3+
4+
#include <SDL2/SDL.h>
5+
#include <SDL2/SDL_opengl.h>
6+
7+
#include <stdlib.h> //rand()
8+
9+
static bool quitting = false;
10+
static float r = 0.0f;
11+
static SDL_Window *window = NULL;
12+
static SDL_GLContext gl_context;
13+
static SDL_Renderer *renderer = NULL;
14+
15+
void render() {
16+
SDL_GL_MakeCurrent(window, gl_context);
17+
r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
18+
19+
glClearColor(r, 0.4f, 0.1f, 1.0f);
20+
glClear(GL_COLOR_BUFFER_BIT);
21+
22+
SDL_GL_SwapWindow(window);
23+
}
24+
25+
26+
int SDLCALL watch(void *userdata, SDL_Event* event) {
27+
28+
if (event->type == SDL_APP_WILLENTERBACKGROUND) {
29+
quitting = true;
30+
}
31+
32+
return 1;
33+
}
34+
35+
int main(int argc, char *argv[]) {
36+
37+
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS) != 0) {
38+
SDL_Log("Failed to initialize SDL: %s", SDL_GetError());
39+
return 1;
40+
}
41+
42+
window = SDL_CreateWindow("title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 512, 512, SDL_WINDOW_OPENGL);
43+
44+
gl_context = SDL_GL_CreateContext(window);
45+
46+
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
47+
if (!renderer) {
48+
SDL_Log("Failed to SDL Renderer: %s", SDL_GetError());
49+
return -1;
50+
}
51+
52+
SDL_AddEventWatch(watch, NULL);
53+
54+
while (!quitting) {
55+
SDL_Event event;
56+
while (SDL_PollEvent(&event) ) {
57+
if (event.type == SDL_QUIT) {
58+
quitting = true;
59+
}
60+
}
61+
62+
render();
63+
SDL_Delay(2);
64+
}
65+
66+
SDL_DelEventWatch(watch, NULL);
67+
SDL_GL_DeleteContext(gl_context);
68+
SDL_DestroyWindow(window);
69+
SDL_Quit();
70+
71+
return 0;
72+
}

0 commit comments

Comments
 (0)