Parameterise some bits for cool animations and make fullscreen
This commit is contained in:
78
main.c
78
main.c
@@ -5,8 +5,11 @@
|
||||
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <assert.h>
|
||||
#include <complex.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -21,14 +24,22 @@
|
||||
#define PRESENT_MODE_BUFFER_SIZE 8
|
||||
#define SWAPCHAIN_IMG_BUFFER_SIZE 4
|
||||
|
||||
#define MAX_SHADER_SIZE (4 * 1024)
|
||||
#define MAX_SHADER_SIZE (8 * 1024)
|
||||
|
||||
typedef struct {
|
||||
float width, height;
|
||||
#ifdef JULIA
|
||||
struct {
|
||||
float x, y;
|
||||
} shift;
|
||||
float zoom;
|
||||
float re, im;
|
||||
} julia;
|
||||
#endif
|
||||
struct {
|
||||
float re, im;
|
||||
} centre;
|
||||
float scale;
|
||||
#ifdef POWRATE
|
||||
float zpow;
|
||||
#endif
|
||||
} params_t;
|
||||
|
||||
static const char *layers[] = { "VK_LAYER_KHRONOS_validation" };
|
||||
@@ -62,14 +73,18 @@ int main(void)
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
GLFWwindow *window
|
||||
= glfwCreateWindow(900, 900, "GPU Fractal", NULL, NULL);
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
GLFWwindow *window = glfwCreateWindow(
|
||||
mode->width, mode->height, "GPU Fractal", monitor, NULL);
|
||||
/* GLFWwindow *window */
|
||||
/* = glfwCreateWindow(900, 900, "GPU Fractal", NULL, NULL); */
|
||||
assert(window);
|
||||
|
||||
// Initialise Vulkan instance.
|
||||
const VkApplicationInfo app_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pApplicationName = "Vulkan Test",
|
||||
.pApplicationName = "GPU Fractal",
|
||||
.applicationVersion = VK_MAKE_VERSION(1, 0, 0),
|
||||
.pEngineName = "No Engine",
|
||||
.engineVersion = VK_MAKE_VERSION(1, 0, 0),
|
||||
@@ -461,16 +476,41 @@ int main(void)
|
||||
result = vkCreateFence(dev, &fence_config, NULL, &in_flight);
|
||||
assert(result == VK_SUCCESS);
|
||||
|
||||
// Prepare parameters
|
||||
params_t params = {
|
||||
.width = (float)swapchain_extent.width,
|
||||
.height = (float)swapchain_extent.height,
|
||||
.shift = {
|
||||
.x = -0.743643887037158704752191506114774,
|
||||
.y = 0.131825904205311970493132056385139,
|
||||
#ifdef JULIA
|
||||
.julia = {
|
||||
#ifdef JULIA_C_RE
|
||||
.re = JULIA_C_RE,
|
||||
#endif
|
||||
#ifdef JULIA_C_IM
|
||||
.im = JULIA_C_IM,
|
||||
#endif
|
||||
},
|
||||
.zoom = 1.0,
|
||||
#endif
|
||||
#if defined(CENTRE_RE) || defined(CENTRE_IM)
|
||||
.centre = {
|
||||
#ifdef CENTRE_RE
|
||||
.re = CENTRE_RE,
|
||||
#endif
|
||||
#ifdef CENTRE_IM
|
||||
.im = CENTRE_IM,
|
||||
#endif
|
||||
},
|
||||
#endif
|
||||
.scale = 1.0,
|
||||
#ifdef POWRATE
|
||||
.zpow = 2.0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef JULIA_DTHETA
|
||||
const double dtheta = JULIA_DTHETA;
|
||||
const double complex rotz = cexp(I * dtheta);
|
||||
#endif
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
@@ -548,8 +588,20 @@ int main(void)
|
||||
result = vkQueuePresentKHR(queue, &present_info);
|
||||
assert(result == VK_SUCCESS);
|
||||
|
||||
// Increment zoom
|
||||
params.zoom *= 0.99;
|
||||
#ifdef JULIA_DTHETA
|
||||
double complex julia = params.julia.re + I * params.julia.im;
|
||||
julia *= rotz;
|
||||
params.julia.re = (float)creal(julia);
|
||||
params.julia.im = (float)cimag(julia);
|
||||
#endif
|
||||
|
||||
#ifdef ZOOMRATE
|
||||
params.scale *= (1 - ZOOMRATE);
|
||||
#endif
|
||||
|
||||
#ifdef POWRATE
|
||||
params.zpow += POWRATE;
|
||||
#endif
|
||||
}
|
||||
|
||||
vkDeviceWaitIdle(dev);
|
||||
|
||||
Reference in New Issue
Block a user