From 3336f27b5a9e8201f6ac37c6cfede92941bce643 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 7 Dec 2017 22:56:47 +1100 Subject: [PATCH] [host] added sync-test application --- host/Looking Glass.sln | 16 +++ host/sync-test/main.c | 105 ++++++++++++++ host/sync-test/packages.config | 8 ++ host/sync-test/sync-test.vcxproj | 172 +++++++++++++++++++++++ host/sync-test/sync-test.vcxproj.filters | 25 ++++ 5 files changed, 326 insertions(+) create mode 100644 host/sync-test/main.c create mode 100644 host/sync-test/packages.config create mode 100644 host/sync-test/sync-test.vcxproj create mode 100644 host/sync-test/sync-test.vcxproj.filters diff --git a/host/Looking Glass.sln b/host/Looking Glass.sln index d80e69ba..c06c672b 100644 --- a/host/Looking Glass.sln +++ b/host/Looking Glass.sln @@ -5,22 +5,38 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "looking-glass-host", "looking-glass-host.vcxproj", "{D439DE3E-32FB-4599-8B5D-C92674D400D4}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sync-test", "sync-test\sync-test.vcxproj", "{6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|ARM = Release|ARM Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Debug|ARM.ActiveCfg = Debug|Win32 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Debug|x64.ActiveCfg = Debug|x64 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Debug|x64.Build.0 = Debug|x64 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Debug|x86.ActiveCfg = Debug|Win32 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Debug|x86.Build.0 = Debug|Win32 + {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Release|ARM.ActiveCfg = Release|Win32 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Release|x64.ActiveCfg = Release|x64 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Release|x64.Build.0 = Release|x64 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Release|x86.ActiveCfg = Release|Win32 {D439DE3E-32FB-4599-8B5D-C92674D400D4}.Release|x86.Build.0 = Release|Win32 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Debug|ARM.ActiveCfg = Debug|Win32 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Debug|x64.ActiveCfg = Debug|x64 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Debug|x64.Build.0 = Debug|x64 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Debug|x86.ActiveCfg = Debug|Win32 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Debug|x86.Build.0 = Debug|Win32 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Release|ARM.ActiveCfg = Release|Win32 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Release|x64.ActiveCfg = Release|x64 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Release|x64.Build.0 = Release|x64 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Release|x86.ActiveCfg = Release|Win32 + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/host/sync-test/main.c b/host/sync-test/main.c new file mode 100644 index 00000000..f31582f3 --- /dev/null +++ b/host/sync-test/main.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include + +int main(int argc, char * argv[]) +{ + SDL_Window * window; + SDL_Renderer * renderer; + + TTF_Init(); + SDL_Init(SDL_INIT_VIDEO); + window = SDL_CreateWindow("sync-test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1000, 1040, SDL_WINDOW_RESIZABLE); + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + + SDL_Event event; + bool running = true; + unsigned int frameCount = 0; + Uint32 fpsFrame = 0; + Uint32 fpsStart = SDL_GetTicks(); + float fps = 0.0f; + TTF_Font * fpsFont = NULL; + SDL_Rect fpsTextRect = {5, 5}; + SDL_Texture * fpsText = NULL; + + int boxX = 100; + int boxY = 100; + + fpsFont = TTF_OpenFont("C:\\Windows\\Fonts\\cour.ttf", 24); + + while (running) + { + while (SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_QUIT: + running = false; + break; + + case SDL_KEYUP: + switch(event.key.keysym.scancode) + { + case SDL_SCANCODE_ESCAPE: + running = false; + break; + + case SDL_SCANCODE_F11: + SDL_SetWindowFullscreen(window, (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); + break; + } + + case SDL_WINDOWEVENT: + switch (event.window.event) + { + case SDL_WINDOWEVENT_RESIZED: + boxX = event.window.data1 / 10; + boxY = (event.window.data2 - 40) / 10; + break; + } + } + + SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE); + SDL_RenderClear(renderer); + + SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, SDL_ALPHA_OPAQUE); + for (int y = 0; y < 10; ++y) + for (int x = 0; x < 10; ++x) + { + const SDL_Rect rect = { x * boxX, y * boxY + 40, boxX, boxY}; + if (y * 10 + x == frameCount % 100) + SDL_RenderFillRect(renderer, &rect); + else + SDL_RenderDrawRect(renderer, &rect); + } + + if (SDL_GetTicks() - fpsStart > 1000) + { + const float delta = (float)(SDL_GetTicks() - fpsStart) / 1000.0f; + const unsigned int frames = frameCount - fpsFrame; + fps = (float)frames / delta; + + fpsStart = SDL_GetTicks(); + fpsFrame = frameCount; + } + + const SDL_Color c = {0x00, 0xff, 0x00, 0xff}; + char text[128]; + snprintf(text, sizeof(text), "FPS: %5.2f, Frame: %05u \"F11\" to toggle Full Screen", fps, frameCount); + SDL_Surface * fpsSurf = TTF_RenderText_Solid(fpsFont, text, c); + if (fpsText) + SDL_DestroyTexture(fpsText); + fpsText = SDL_CreateTextureFromSurface(renderer, fpsSurf); + fpsTextRect.w = fpsSurf->w; + fpsTextRect.h = fpsSurf->h; + SDL_FreeSurface(fpsSurf); + SDL_RenderCopy(renderer, fpsText, NULL, &fpsTextRect); + + SDL_RenderPresent(renderer); + ++frameCount; + } + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + return 0; +} \ No newline at end of file diff --git a/host/sync-test/packages.config b/host/sync-test/packages.config new file mode 100644 index 00000000..575808e5 --- /dev/null +++ b/host/sync-test/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/host/sync-test/sync-test.vcxproj b/host/sync-test/sync-test.vcxproj new file mode 100644 index 00000000..d569e8a4 --- /dev/null +++ b/host/sync-test/sync-test.vcxproj @@ -0,0 +1,172 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {6CC4DA30-6FBD-4ACA-9BA6-2DE731032800} + Win32Proj + synctest + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + + + Level3 + Disabled + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + \ No newline at end of file diff --git a/host/sync-test/sync-test.vcxproj.filters b/host/sync-test/sync-test.vcxproj.filters new file mode 100644 index 00000000..978b5204 --- /dev/null +++ b/host/sync-test/sync-test.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + + \ No newline at end of file