Separate vulkan code into gpu module
This commit is contained in:
1 parent
51c01a2f9e
commit
d4214941b1
4 files changed
+311
-236
No files matched your search
@@ -0,0 +1,60 @@
|
||||
#include "gpu.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
static const vertex_t vertices[] = {
|
||||
{ { 0.0, -0.5 }, { 1.0, 0.0, 0.0 } },
|
||||
{ { 0.5, 0.5 }, { 0.0, 1.0, 0.0 } },
|
||||
{ { -0.5, 0.5 }, { 0.0, 0.0, 1.0 } },
|
||||
};
|
||||
|
||||
static void
|
||||
key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
(void)window;
|
||||
(void)scancode;
|
||||
(void)mods;
|
||||
|
||||
switch (key) {
|
||||
case GLFW_KEY_Q:
|
||||
if (action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Set up window
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
GLFWwindow *window = glfwCreateWindow(800, 600, "Foo", nullptr, nullptr);
|
||||
assert(window);
|
||||
|
||||
// Register input callbacks
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
// Initialise GPU
|
||||
const gpu_config_t gpu_config = {
|
||||
.application_name = "Foo",
|
||||
.window = window,
|
||||
.vertex_data = vertices,
|
||||
.vertex_data_size = sizeof(vertices),
|
||||
};
|
||||
gpu_ctx_t gpu;
|
||||
gpu_init(&gpu, &gpu_config);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
gpu_render(&gpu);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
gpu_cleanup(&gpu);
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user