MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "mxvk/argz.hpp"
2#include "mxvk/mxvk.hpp"
4#include <cstdlib>
5#include <format>
6#include <iostream>
7#include <string>
8
9namespace example {
10 class ExampleWindow : public mxvk::VK_Window {
11 std::string current_path = ".";
12
13 public:
14 ExampleWindow(const std::string path, const std::string &text, int width, int height, bool fullscreen, bool enable_vsync) : mxvk::VK_Window(text, width, height, fullscreen, MXVK_VALIDATION, enable_vsync) {
15 current_path = path.empty() ? std::string(text_example_ASSET_DIR) : path;
16 setFont(current_path + "/data/font.ttf", 24);
17 }
18
19 void event(SDL_Event &e) override {
20 if (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE) {
21 exit();
22 }
23 }
24
25 void proc() override {
26 printText("Hello World", 15, 15, SDL_Color{255, 255, 255, 255});
27 }
28 };
29} // namespace example
30
31int main(int argc, char **argv) {
32 try {
33 Arguments args = proc_args(argc, argv);
34 example::ExampleWindow ex_window(args.path, "VK_Example", args.width, args.height, args.fullscreen, args.enable_vsync);
35 ex_window.loop();
36 } catch (mxvk::Exception &e) {
37 std::cerr << std::format("mxvk: Exception: {}\n", e.text());
38 return EXIT_FAILURE;
39 } catch (ArgException<std::string> &e) {
40 std::cerr << std::format("mxvk: Argument Exception: {}\n", e.text());
41 }
42 return EXIT_SUCCESS;
43}
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 main.cpp:19
void proc() override
Execute one processing/update step.
Definition main.cpp:25
ExampleWindow(const std::string path, const std::string &text, int width, int height, bool fullscreen, bool enable_vsync)
Definition main.cpp:14
std::string text() const
void loop()
Run the main event/render loop.
Definition mxvk.cpp:600
void exit()
Request loop termination.
Definition mxvk.cpp:1126
VK_Window()=default
Construct an empty window object.
void setFont(const std::string &fontPath, int fontSize=24)
Set the active text-render font.
Definition mxvk.cpp:2991
void printText(const std::string &text, int x, int y, const SDL_Color &col)
Queue a text string for rendering during the current frame.
Definition mxvk.cpp:3018
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