Gears-C/src/platform_windows.c

211 lines
3.1 KiB
C

HINSTANCE win32_instance = {};
Window win32_window = {};
LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param)
{
LRESULT result = 0;
switch (message)
{
case WM_SIZE:
{
OutputDebugStringA("WM_SIZE\n");
} break;
case WM_DESTROY:
{
OutputDebugStringA("WM_DESTROY\n");
} break;
case WM_CLOSE:
{
OutputDebugStringA("WM_CLOSE\n");
} break;
case WM_ACTIVATEAPP:
{
OutputDebugStringA("WM_ACTIVATEAPP\n");
} break;
default:
{
result = DefWindowProc(window, message, w_param, l_param);
} break;
}
return result;
}
int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line, int show_code)
{
win32_instance = instance;
WNDCLASS window_class = {
.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
.lpfnWndProc = WindowProc,
.hInstance = instance,
.lpszClassName = "GearsWindowClass",
};
if (RegisterClass(&window_class))
{
HWND window_handle = CreateWindowEx(
0,
window_class.lpszClassName,
"Video Game",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
instance,
0
);
if (window_handle)
{
while (true)
{
MSG message;
BOOL message_result = GetMessage(&message, 0, 0, 0);
if (message_result > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}
else
{
break;
}
}
}
}
}
b32 _LoadLib(const char *name, Library *out_lib)
{
b32 success = true;
out_lib->module = LoadLibraryA("vulkan-1.dll");
if (!out_lib->module)
success = false;
return success;
}
b32 _LoadFn(const char *name, Library *lib, Function *out_fn)
{
b32 success = true;
out_fn->fn = GetProcAddress(lib->module, name);
if (!out_fn->fn)
success = false;
return success;
}
b32 _InitPlatform()
{
b32 success = true;
return success;
}
rawptr _MemAlloc(isize size)
{
return NULL;
}
rawptr _MemAllocZeroed(isize size)
{
return NULL;
}
isize _GetPageSize()
{
return 0;
}
i32 _EPrint(void const *str)
{
return 0;
}
i32 _Printf(const char *fmt, ...)
{
return 0;
}
i32 _Printfln(const char *fmt, ...)
{
return 0;
}
i32 _EPrintf(const char *fmt, ...)
{
return 0;
}
b32 _CreateWindow()
{
b32 success = true;
WNDCLASS window_class = {
.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
.lpfnWndProc = WindowProc,
.hInstance = win32_instance,
.lpszClassName = WINDOW_CLASS_NAME,
};
ATOM r_class_atom = RegisterClass(&window_class);
if (!r_class_atom)
success = false;
if (success)
{
HWND window_handle = CreateWindowEx(
0,
window_class.lpszClassName,
"Video Game",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
win32_instance,
0
);
if (!window_handle)
success = false;
else
win32_window.handle = window_handle;
}
return success;
}
Window *_GetWindow()
{
return NULL;
}
b32 _GetWindowEvent(WindowEvent *event)
{
b32 success = true;
return success;
}
void _WaitForWindowEvent(WindowEvent *event)
{
}
WindowSize _GetWindowSize()
{
return (WindowSize){ .w = 0, .h = 0 };
}