MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
fire.cpp
Go to the documentation of this file.
1#include "mxvk/argz.hpp"
2#include "mxvk/mxvk.hpp"
4
5#include <algorithm>
6#include <cstdlib>
7#include <format>
8#include <iostream>
9#include <string>
10
11namespace example {
12 class FireWindow : public mxvk::VK_Window {
13 public:
14 FireWindow(const std::string &path, int width, int height, bool fullscreen, bool enable_vsync)
15 : mxvk::VK_Window("Fire - Procedural Shader", width, height, fullscreen, MXVK_VALIDATION, enable_vsync),
16 shader_root((path.empty() ? std::string(FIRE_ASSET_DIR) : path) + "/data") {
17 setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
18 attachPostProcessingShader(shader_root + "/fire.frag.spv");
21 }
22
23 void event(SDL_Event &e) override {
24 if (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE) {
25 exit();
26 } else if (e.type == SDL_EVENT_MOUSE_WHEEL) {
27 zoom = std::clamp(zoom + e.wheel.y * 0.16f, 0.25f, 4.40f);
28 }
29 }
30
31 void proc() override {
33 0.0f,
34 0.5f,
35 0.78f,
36 zoom);
37 }
38
39 private:
40 std::string shader_root;
41 float zoom = 1.0f;
42 };
43} // namespace example
44
45int main(int argc, char **argv) {
46 try {
47 const Arguments args = proc_args(argc, argv);
48 example::FireWindow window(args.path, args.width, args.height, args.fullscreen, args.enable_vsync);
49 window.loop();
50 } catch (const mxvk::Exception &e) {
51 std::cerr << std::format("mxvk: Exception: {}\n", e.text());
52 return EXIT_FAILURE;
53 } catch (const ArgException<std::string> &e) {
54 std::cerr << std::format("mxvk: Argument Exception: {}\n", e.text());
55 return EXIT_FAILURE;
56 }
57 return EXIT_SUCCESS;
58}
Lightweight, header-only, template command-line argument parser.
Arguments proc_args(int &argc, char **argv)
Parse standard libmx2 command-line options from main()'s argv.
Definition argz.hpp:872
Exception thrown by Argz::proc() on unrecognised or malformed options.
Definition argz.hpp:178
void event(SDL_Event &e) override
Handle one SDL event.
Definition fire.cpp:23
void proc() override
Execute one processing/update step.
Definition fire.cpp:31
FireWindow(const std::string &path, int width, int height, bool fullscreen, bool enable_vsync)
Definition fire.cpp:14
std::string text() const
Main Vulkan window wrapper for MXVK.
Definition mxvk.hpp:37
void loop()
Run the main event/render loop.
Definition mxvk.cpp:600
void setClearColor(float r, float g, float b, float a=1.0f)
Set the per-frame color attachment clear color.
Definition mxvk.cpp:593
void exit()
Request loop termination.
Definition mxvk.cpp:1126
VK_Sprite * attachPostProcessingShader(const std::string &fragmentShaderPath, float p1=0.0f, float p2=0.0f, float p3=0.0f, float p4=0.0f)
Attach a full-screen post-processing fragment shader.
Definition mxvk.cpp:1154
VK_Window()=default
Construct an empty window object.
void setPostProcessingEnabled(bool enabled)
Definition mxvk.hpp:284
void setPostProcessingShaderParams(float p1=0.0f, float p2=0.0f, float p3=0.0f, float p4=0.0f)
Set the post-processing shader params passed as a vec4 push constant.
Definition mxvk.cpp:1227
void setPostProcessingShaderTimeEnabled(bool enabled)
Keep shader param 1 updated with elapsed render time in seconds.
Definition mxvk.cpp:1248
int main(void)
Definition main.cpp:7
#define MXVK_VALIDATION
Definition mxvk.hpp:27
Utilities for loading and saving PNG images.
Definition mxvk.hpp:30
Plain data structure returned by proc_args() with all common libmx2 CLI options.
Definition argz.hpp:730
bool fullscreen
Whether fullscreen mode was requested.
Definition argz.hpp:736
bool enable_vsync
Enable FIFO present mode / v-sync (--enable-vsync).
Definition argz.hpp:750
int height
Viewport height in pixels (default: 720).
Definition argz.hpp:733
std::string path
Asset root; proc_args() defaults it to the executable directory.
Definition argz.hpp:735
int width
Viewport width in pixels (default: 1280).
Definition argz.hpp:732