I am making a C library that abstracts window creation with support for the new Vulkan API under a unified API; I have a github repository that you can check out.
main.c
#include "vkwf.h"
int main()
{
VKWFWindow* window = VKWFCreateWindow("Test Window", 800, 600);
while (!VKWFWindowShouldClose(window))
{
VKWFWindowUpdate(window);
}
free(window);
return 0;
}
The way I am handling this is creating a general vkwf.h
file, that includes a list of functions, like this:
vkwf.h
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifdef VKWF_PLATFORM_WINDOWS
#include "win32_window.h"
#elif VKWF_PLATFORM_MACOS
#include "macos_window.h"
#elif VKWF_PLATFORM_LINUX
#include "linux_window.h"
#endif
VKWFWindow* VKWFCreateWindow(const char* title, int width, int height)
{
return VKWFPlatformCreateWindow(title, width, height);
}
VKWFBool VKWFWindowShouldClose(VKWFWindow* window)
{
return VKWFPlatformWindowShouldClose(window);
}
void VKWFWindowUpdate(VKWFWindow* window)
{
VKWFPlatformUpdate(window);
}
void VKWFDestroyWindow(VKWFWindow* window)
{
VKWFPlatformDestroyWindow(window);
}
#ifdef __cplusplus
}
#endif
All VKWFPlatformX()
functions are functions that get defined by the platform_window.h
files, like this:
win32_window.h (short)
#define VKWFPlatformCreateWindow(title,width,height) VKWFWin32CreateWindow(title,width,height)
#define VKWFPlatformWindowShouldClose(window) VKWFWin32WindowShouldClose(window)
#define VKWFPlatformUpdate(window) VKWFWin32Update(window)
#define VKWFPlatformDestroyWindow(window) VKWFWin32DestroyWindow(window)
Does this look like a good approach? Are there any drawbacks, or things that i could improve?