initial commit
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 31 Aug 2024 03:38:14 +0000 (06:38 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 31 Aug 2024 03:38:14 +0000 (06:38 +0300)
.gitignore [new file with mode: 0644]
README.md [new file with mode: 0644]
src/main.c [new file with mode: 0644]
src/winsys.h [new file with mode: 0644]
src/winsys_w32.c [new file with mode: 0644]
vkraytest.sln [new file with mode: 0644]
vkraytest.vcxproj [new file with mode: 0644]
vkraytest.vcxproj.filters [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..59e1e31
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.d
+*.swp
+Debug/
+Release/
+x64/
+*.vcxproj.user
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..9ec6636
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+vkraytest
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..3ba70f7
--- /dev/null
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <vulkan/vulkan.h>
+#include "winsys.h"
+
+static int win_width, win_height;
+
+int main(int argc, char **argv)
+{
+       if(create_window("vulkan ray test", 800, 600) == -1) {
+               return 1;
+       }
+
+       for(;;) {
+               handle_events();
+               if(quit) break;
+
+               display();
+       }
+
+       destroy_window();
+       return 0;
+}
+
+void display(void)
+{
+       swap_buffers();
+}
+
+void reshape(int x, int y)
+{
+       win_width = x;
+       win_height = y;
+}
+
+void keypress(int key)
+{
+       switch(key) {
+       case 27:
+               quit = 1;
+               break;
+       }
+}
+
+void keyrelease(int key)
+{
+}
+
+void mousebutton(int bn, int st, int x, int y)
+{
+}
+
+void mousemotion(int x, int y)
+{
+}
\ No newline at end of file
diff --git a/src/winsys.h b/src/winsys.h
new file mode 100644 (file)
index 0000000..28fa015
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef WINSYS_H_
+#define WINSYS_H_
+
+#ifdef __unix__
+#define WSYS_X11
+#include <X11/Xlib.h>
+
+extern Display *dpy;
+extern Window win;
+
+#elif defined(_WIN32)
+#define WSYS_WIN32
+#include <windows.h>
+
+extern HWND win;
+#else
+#error "unknown window system"
+#endif
+
+extern int quit;
+
+int create_window(const char *title, int xsz, int ysz);
+void destroy_window(void);
+void handle_events(void);
+void swap_buffers(void);
+
+/* app-defined functions */
+void display(void);
+void reshape(int x, int y);
+void keypress(int key);
+void keyrelease(int key);
+void mousebutton(int bn, int st, int x, int y);
+void mousemotion(int x, int y);
+
+#endif /* WINSYS_H_ */
diff --git a/src/winsys_w32.c b/src/winsys_w32.c
new file mode 100644 (file)
index 0000000..7098c7f
--- /dev/null
@@ -0,0 +1,193 @@
+#include <stdio.h>
+#include "winsys.h"
+
+HWND win;
+int quit;
+
+static int win_width, win_height, mapped;
+
+static int init_done, reshape_pending;
+static HINSTANCE hinst;
+static HDC dc;
+static WNDCLASSEX wc;
+
+static int translate_vkey(int vkey);
+static void calc_win_rect(RECT *rect, int x, int y, int w, int h);
+static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
+
+int create_window(const char *title, int xsz, int ysz)
+{
+       RECT rect;
+
+       if(!init_done) {
+               hinst = GetModuleHandle(0);
+
+               wc.cbSize = sizeof wc;
+               wc.hbrBackground = GetStockObject(BLACK_BRUSH);
+               wc.hCursor = LoadCursor(0, IDC_ARROW);
+               wc.hIcon = wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
+               wc.hInstance = hinst;
+               wc.lpfnWndProc = handle_msg;
+               wc.lpszClassName = "lospoulos";
+               wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+               if(!RegisterClassEx(&wc)) {
+                       fprintf(stderr, "failed to register window class\n");
+                       return -1;
+               }
+               init_done = 1;
+       }
+
+       rect.left = GetSystemMetrics(SM_CXSCREEN) / 3;
+       rect.top = GetSystemMetrics(SM_CYSCREEN) / 3;
+       calc_win_rect(&rect, rect.left, rect.top, xsz, ysz);
+
+       if(!(win = CreateWindow("lospoulos", title, WS_OVERLAPPEDWINDOW, rect.left, rect.top, rect.right - rect.left,
+                       rect.bottom - rect.top, 0, 0, hinst, 0))) {
+               return -1;
+       }
+       dc = GetDC(win);
+       ShowWindow(win, 1);
+       SetForegroundWindow(win);
+       SetFocus(win);
+
+       reshape_pending = 1;
+       return 0;
+}
+
+void destroy_window(void)
+{
+}
+
+void handle_events(void)
+{
+       MSG msg;
+       while(PeekMessage(&msg, win, 0, 0, PM_REMOVE)) {
+               TranslateMessage(&msg);
+               DispatchMessage(&msg);
+               if(quit) return;
+       }
+
+       if(reshape_pending) {
+               reshape_pending = 0;
+               reshape(win_width, win_height);
+       }
+}
+
+void swap_buffers(void)
+{
+}
+
+static void calc_win_rect(RECT *rect, int x, int y, int w, int h)
+{
+       rect->left = x;
+       rect->top = y;
+       rect->right = x + w;
+       rect->bottom = y + h;
+       AdjustWindowRect(rect, WS_OVERLAPPEDWINDOW, 0);
+}
+
+static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
+{
+       static int mouse_x, mouse_y;
+       int x, y, bn, key;
+
+       switch(msg) {
+       case WM_CLOSE:
+       case WM_DESTROY:
+               PostQuitMessage(0);
+               quit = 1;
+               break;
+
+       case WM_PAINT:
+               ValidateRect(win, 0);
+               break;
+
+       case WM_SIZE:
+               x = lparam & 0xffff;
+               y = lparam >> 16;
+               if(x != win_width || y != win_height) {
+                       win_width = x;
+                       win_height = y;
+                       reshape_pending = 1;
+               }
+               break;
+
+       case WM_SHOWWINDOW:
+               mapped = wparam;
+               break;
+
+       case WM_KEYDOWN:
+       case WM_SYSKEYDOWN:
+               key = translate_vkey(wparam);
+               keypress(key);
+               break;
+
+       case WM_KEYUP:
+       case WM_SYSKEYUP:
+               key = translate_vkey(wparam);
+               keyrelease(key);
+               break;
+
+       case WM_LBUTTONDOWN:
+               bn = 0;
+               if(0)
+       case WM_MBUTTONDOWN:
+               bn = 1;
+               if(0)
+       case WM_RBUTTONDOWN:
+               bn = 2;
+               mousebutton(bn, 1, lparam & 0xffff, lparam >> 16);
+               break;
+
+       case WM_LBUTTONUP:
+               bn = 0;
+               if(0)
+       case WM_MBUTTONUP:
+               bn = 1;
+               if(0)
+       case WM_RBUTTONUP:
+               bn = 2;
+               mousebutton(bn, 0, lparam & 0xffff, lparam >> 16);
+               break;
+
+       case WM_MOUSEMOVE:
+               mousemotion(lparam & 0xffff, lparam >> 16);
+               break;
+
+       default:
+               return DefWindowProc(win, msg, wparam, lparam);
+       }
+
+       return 0;
+}
+
+static int translate_vkey(int vkey)
+{
+       switch(vkey) {
+       /*case VK_PRIOR: return GLUT_KEY_PAGE_UP;
+       case VK_NEXT: return GLUT_KEY_PAGE_DOWN;
+       case VK_END: return GLUT_KEY_END;
+       case VK_HOME: return GLUT_KEY_HOME;
+       case VK_LEFT: return GLUT_KEY_LEFT;
+       case VK_UP: return GLUT_KEY_UP;
+       case VK_RIGHT: return GLUT_KEY_RIGHT;
+       case VK_DOWN: return GLUT_KEY_DOWN;*/
+       case VK_OEM_1: return ';';
+       case VK_OEM_2: return '/';
+       case VK_OEM_3: return '`';
+       case VK_OEM_4: return '[';
+       case VK_OEM_5: return '\\';
+       case VK_OEM_6: return ']';
+       case VK_OEM_7: return '\'';
+       default:
+               break;
+       }
+
+       if(vkey >= 'A' && vkey <= 'Z') {
+               vkey += 32;
+       }/* else if(vkey >= VK_F1 && vkey <= VK_F12) {
+               vkey -= VK_F1 + GLUT_KEY_F1;
+       }*/
+
+       return vkey;
+}
\ No newline at end of file
diff --git a/vkraytest.sln b/vkraytest.sln
new file mode 100644 (file)
index 0000000..6c965ec
--- /dev/null
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.34928.147
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vkraytest", "vkraytest.vcxproj", "{A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|x64 = Debug|x64
+               Debug|x86 = Debug|x86
+               Release|x64 = Release|x64
+               Release|x86 = Release|x86
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Debug|x64.ActiveCfg = Debug|x64
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Debug|x64.Build.0 = Debug|x64
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Debug|x86.ActiveCfg = Debug|Win32
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Debug|x86.Build.0 = Debug|Win32
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Release|x64.ActiveCfg = Release|x64
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Release|x64.Build.0 = Release|x64
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Release|x86.ActiveCfg = Release|Win32
+               {A26190AA-3FAB-4732-BB30-CD7E6D8AF6AD}.Release|x86.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+       GlobalSection(ExtensibilityGlobals) = postSolution
+               SolutionGuid = {E533D5C4-E32A-44E5-B35C-DA2BEBC2F9AD}
+       EndGlobalSection
+EndGlobal
diff --git a/vkraytest.vcxproj b/vkraytest.vcxproj
new file mode 100644 (file)
index 0000000..c5b0238
--- /dev/null
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" 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>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <VCProjectVersion>17.0</VCProjectVersion>
+    <Keyword>Win32Proj</Keyword>
+    <ProjectGuid>{a26190aa-3fab-4732-bb30-cd7e6d8af6ad}</ProjectGuid>
+    <RootNamespace>vkraytest</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="Shared">
+  </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>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <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|x64'">
+    <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'">
+    <ExternalIncludePath>C:\VulkanSDK\1.3.290.0\Include;$(ExternalIncludePath)</ExternalIncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ExternalIncludePath>C:\VulkanSDK\1.3.290.0\Include;$(ExternalIncludePath)</ExternalIncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ExternalIncludePath>C:\VulkanSDK\1.3.290.0\Include;$(ExternalIncludePath)</ExternalIncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ExternalIncludePath>C:\VulkanSDK\1.3.290.0\Include;$(ExternalIncludePath)</ExternalIncludePath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="src\main.c" />
+    <ClCompile Include="src\winsys_w32.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="src\winsys.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/vkraytest.vcxproj.filters b/vkraytest.vcxproj.filters
new file mode 100644 (file)
index 0000000..ea7f6f4
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="src">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="src\main.c">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\winsys_w32.c">
+      <Filter>src</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="src\winsys.h">
+      <Filter>src</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>
\ No newline at end of file