MXVK Vulkan Framework 0.35.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#if defined(MXVK_USE_EIGEN_MATH)
6#else
7#include "mxvk/mxvk_math.h"
8#endif
9#include "mxvk/mxvk_png.hpp"
10
11#include <SDL3/SDL.h>
12
13#include <algorithm>
14#include <array>
15#include <cstdint>
16#include <cstdlib>
17#include <filesystem>
18#include <format>
19#include <iostream>
20#include <memory>
21#include <string>
22#include <vector>
23
24namespace {
25 class SurfaceDeleter {
26 public:
27 void operator()(SDL_Surface *surface) const { SDL_DestroySurface(surface); }
28 };
29
30 using SurfacePtr = std::unique_ptr<SDL_Surface, SurfaceDeleter>;
31
32 SurfacePtr create_frame_surface(int width, int height) {
33 SurfacePtr surface(SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA32));
34 if (!surface) {
35 throw mxvk::Exception(std::format("Failed to create 3dmath_texture frame surface: {}", SDL_GetError()));
36 }
37 return surface;
38 }
39
40 struct Texture {
41 int width = 0;
42 int height = 0;
43 std::vector<mxvk::MXCOLOR> pixels;
44
45 [[nodiscard]] mxvk::MXCOLOR sample(float u, float v) const {
46 if (width <= 0 || height <= 0 || pixels.empty()) {
47 return mxvk::MXVK_RGB(255, 255, 255);
48 }
49
50 u = std::clamp(u, 0.0f, 1.0f);
51 v = std::clamp(v, 0.0f, 1.0f);
52 const int x = std::clamp(static_cast<int>(u * static_cast<float>(width - 1) + 0.5f), 0, width - 1);
53 const int y = std::clamp(static_cast<int>(v * static_cast<float>(height - 1) + 0.5f), 0, height - 1);
54 return pixels[static_cast<std::size_t>(y * width + x)];
55 }
56
57 [[nodiscard]] mxvk::MXCOLOR sample_nearest(float u, float v) const {
58 u = std::clamp(u, 0.0f, 1.0f);
59 v = std::clamp(v, 0.0f, 1.0f);
60 const int x = static_cast<int>(u * static_cast<float>(width - 1) + 0.5f);
61 const int y = static_cast<int>(v * static_cast<float>(height - 1) + 0.5f);
62 return pixels[static_cast<std::size_t>(y * width + x)];
63 }
64 };
65
71
72 struct FaceDraw {
73 std::array<int, 4> indices{};
74 float depth = 0.0f;
75 float intensity = 1.0f;
76 };
77
78 [[nodiscard]] std::string resolve_texture_path(const Arguments &args) {
79 std::string texture_path = !args.filename.empty() ? args.filename : args.texture;
80 if (texture_path.empty()) {
81 throw mxvk::Exception("3dmath_texture: pass a PNG with --filename <file.png> or --texture <file.png>");
82 }
83
84 namespace fs = std::filesystem;
85 fs::path requested(texture_path);
86 if (requested.is_absolute() || fs::exists(requested)) {
87 return requested.string();
88 }
89
90 if (!args.path.empty()) {
91 const fs::path from_asset_path = fs::path(args.path) / requested;
92 if (fs::exists(from_asset_path)) {
93 return from_asset_path.string();
94 }
95 }
96
97 return requested.string();
98 }
99
100 [[nodiscard]] Texture load_texture(const std::string &path) {
101 SurfacePtr loaded(mxvk::LoadPNG(path.c_str()));
102 if (!loaded) {
103 throw mxvk::Exception(std::format("3dmath_texture: failed to load PNG '{}'", path));
104 }
105
106 SurfacePtr rgba(SDL_ConvertSurface(loaded.get(), SDL_PIXELFORMAT_RGBA32));
107 if (!rgba) {
108 throw mxvk::Exception(std::format("3dmath_texture: failed to convert PNG '{}': {}", path, SDL_GetError()));
109 }
110
111 const SDL_PixelFormatDetails *format = SDL_GetPixelFormatDetails(rgba->format);
112 if (format == nullptr) {
113 throw mxvk::Exception(std::format("3dmath_texture: failed to query PNG format '{}': {}", path, SDL_GetError()));
114 }
115
116 Texture texture;
117 texture.width = rgba->w;
118 texture.height = rgba->h;
119 texture.pixels.resize(static_cast<std::size_t>(texture.width * texture.height));
120
121 for (int y = 0; y < texture.height; ++y) {
122 const auto *row = static_cast<const std::uint8_t *>(rgba->pixels) + (static_cast<std::size_t>(y) * static_cast<std::size_t>(rgba->pitch));
123 const auto *src = reinterpret_cast<const std::uint32_t *>(row);
124 for (int x = 0; x < texture.width; ++x) {
125 std::uint8_t r = 0;
126 std::uint8_t g = 0;
127 std::uint8_t b = 0;
128 std::uint8_t a = 0;
129 SDL_GetRGBA(src[x], format, nullptr, &r, &g, &b, &a);
130 texture.pixels[static_cast<std::size_t>(y * texture.width + x)] = (static_cast<mxvk::MXCOLOR>(a) << 24U) | (static_cast<mxvk::MXCOLOR>(r) << 16U) | (static_cast<mxvk::MXCOLOR>(g) << 8U) | static_cast<mxvk::MXCOLOR>(b);
131 }
132 }
133
134 return texture;
135 }
136} // namespace
137
138namespace example {
140 public:
141 Math3DTextureWindow(const Arguments &args, const std::string &title) : mxvk::VK_Window(title, args.width, args.height, args.fullscreen, MXVK_VALIDATION, args.enable_vsync), texture(load_texture(resolve_texture_path(args))), frame_width(args.framebuffer.width), frame_height(args.framebuffer.height), fallback_width(args.width), fallback_height(args.height) {
142 setClearColor(0.012f, 0.015f, 0.022f, 1.0f);
144 }
145
146 void event(SDL_Event &e) override {
147 if (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE) {
148 exit();
149 }
150 if (e.type == SDL_EVENT_MOUSE_WHEEL) {
151 const float delta = (e.wheel.y != 0.0f) ? e.wheel.y : static_cast<float>(e.wheel.integer_y);
152 camera_distance = std::clamp(camera_distance - delta * CAMERA_ZOOM_STEP, MIN_CAMERA_DISTANCE, MAX_CAMERA_DISTANCE);
153 }
154 }
155
156 void proc() override {
157 const int output_width = swapchain_extent.width > 0U ? static_cast<int>(swapchain_extent.width) : fallback_width;
158 const int output_height = swapchain_extent.height > 0U ? static_cast<int>(swapchain_extent.height) : fallback_height;
159
160 ensure_framebuffer();
161 if (frame_sprite == nullptr || frame_surface == nullptr || frame_format == nullptr) {
162 return;
163 }
164
165 const float time = static_cast<float>(SDL_GetTicks()) * 0.001f;
166 clear_frame(mxvk::MXVK_RGB(3, 4, 8));
167
168 const std::array<mxvk::vec4D, 8> cube_vertices = {
169 mxvk::vec4D{-1.0f, -1.0f, -1.0f, 1.0f},
170 mxvk::vec4D{1.0f, -1.0f, -1.0f, 1.0f},
171 mxvk::vec4D{1.0f, 1.0f, -1.0f, 1.0f},
172 mxvk::vec4D{-1.0f, 1.0f, -1.0f, 1.0f},
173 mxvk::vec4D{-1.0f, -1.0f, 1.0f, 1.0f},
174 mxvk::vec4D{1.0f, -1.0f, 1.0f, 1.0f},
175 mxvk::vec4D{1.0f, 1.0f, 1.0f, 1.0f},
176 mxvk::vec4D{-1.0f, 1.0f, 1.0f, 1.0f},
177 };
178
179 mxvk::Mat4D rotation;
180 rotation.BuildXYZ(time * 31.0f, time * 43.0f, time * 17.0f);
181
182 std::array<mxvk::vec4D, 8> camera_vertices{};
183 std::array<mxvk::vec4D, 8> projected{};
184 for (std::size_t i = 0; i < cube_vertices.size(); ++i) {
185 mxvk::vec4D point = rotation.MulVec(cube_vertices[i]);
186 point.z += camera_distance;
187 camera_vertices[i] = point;
188 projected[i] = project_to_screen(point, frame_width, frame_height);
189 }
190
191 const std::array<std::array<int, 4>, 6> cube_faces = {{
192 {0, 3, 2, 1},
193 {4, 5, 6, 7},
194 {0, 4, 7, 3},
195 {1, 2, 6, 5},
196 {3, 7, 6, 2},
197 {0, 1, 5, 4},
198 }};
199
200 mxvk::vec3D light_dir(-0.35f, -0.55f, -1.0f);
201 light_dir.Normalize();
202
203 std::vector<FaceDraw> faces;
204 faces.reserve(cube_faces.size());
205 for (const auto &indices : cube_faces) {
206 const mxvk::vec4D &a = camera_vertices[static_cast<std::size_t>(indices[0])];
207 const mxvk::vec4D &b = camera_vertices[static_cast<std::size_t>(indices[1])];
208 const mxvk::vec4D &c = camera_vertices[static_cast<std::size_t>(indices[2])];
209 mxvk::vec4D normal = mxvk::vec4D().Build(a, b).CrossProduct(mxvk::vec4D().Build(a, c));
210 normal.Normalize();
211
212 const mxvk::vec4D center = (a + b + c + camera_vertices[static_cast<std::size_t>(indices[3])]) * 0.25f;
213 const mxvk::vec4D view_vector(-center.x, -center.y, -center.z, 1.0f);
214 if (normal.DotProduct(view_vector) <= 0.0f) {
215 continue;
216 }
217
218 const float diffuse = std::max(0.0f, normal.DotProduct(mxvk::vec4D(light_dir.x, light_dir.y, light_dir.z, 1.0f)));
219 const float intensity = std::clamp(0.35f + diffuse * 0.65f, 0.0f, 1.0f);
220 faces.push_back({indices, center.z, intensity});
221 }
222
223 std::ranges::sort(faces, [](const FaceDraw &left, const FaceDraw &right) { return left.depth > right.depth; });
224
225 for (const FaceDraw &face : faces) {
226 const auto index0 = static_cast<std::size_t>(face.indices[0]);
227 const auto index1 = static_cast<std::size_t>(face.indices[1]);
228 const auto index2 = static_cast<std::size_t>(face.indices[2]);
229 const auto index3 = static_cast<std::size_t>(face.indices[3]);
230 const TexVertex a{projected[index0], {0.0f, 1.0f}, camera_vertices[index0].z};
231 const TexVertex b{projected[index1], {1.0f, 1.0f}, camera_vertices[index1].z};
232 const TexVertex c{projected[index2], {1.0f, 0.0f}, camera_vertices[index2].z};
233 const TexVertex d{projected[index3], {0.0f, 0.0f}, camera_vertices[index3].z};
234 draw_textured_triangle(a, b, c, face.intensity);
235 draw_textured_triangle(a, c, d, face.intensity);
236 }
237
238 frame_sprite->updateTexture(frame_surface->pixels, frame_width, frame_height, frame_surface->pitch);
239 frame_sprite->drawSpriteRect(0, 0, output_width, output_height);
240 }
241
242 private:
243 Texture texture;
244 SurfacePtr frame_surface;
245 const SDL_PixelFormatDetails *frame_format = nullptr;
246 mxvk::VK_Sprite *frame_sprite = nullptr;
247 int frame_width = 1280;
248 int frame_height = 720;
249 int fallback_width = 1280;
250 int fallback_height = 720;
251 float camera_distance = 4.25f;
252 static constexpr float MIN_CAMERA_DISTANCE = 2.2f;
253 static constexpr float MAX_CAMERA_DISTANCE = 10.0f;
254 static constexpr float CAMERA_ZOOM_STEP = 0.45f;
255
256 void ensure_framebuffer() {
257 if (frame_surface != nullptr) {
258 return;
259 }
260
261 frame_surface = create_frame_surface(frame_width, frame_height);
262 frame_format = SDL_GetPixelFormatDetails(frame_surface->format);
263 if (frame_format == nullptr) {
264 throw mxvk::Exception(std::format("Failed to query 3dmath_texture frame format: {}", SDL_GetError()));
265 }
266
267 clear_frame(mxvk::MXVK_RGB(3, 4, 8));
268 frame_sprite = createSprite(frame_surface.get());
269 frame_sprite->setTextureFilter(VK_FILTER_NEAREST);
270 }
271
272 [[nodiscard]] std::uint32_t map_color(mxvk::MXCOLOR color) const { return SDL_MapRGBA(frame_format, nullptr, mxvk::color_r(color), mxvk::color_g(color), mxvk::color_b(color), mxvk::color_a(color)); }
273
274 void clear_frame(mxvk::MXCOLOR color) { SDL_FillSurfaceRect(frame_surface.get(), nullptr, map_color(color)); }
275
276 void put_shaded_pixel_unchecked(int x, int y, mxvk::MXCOLOR color, std::uint16_t intensity) {
277 auto *row = static_cast<std::uint8_t *>(frame_surface->pixels) + (static_cast<std::size_t>(y) * static_cast<std::size_t>(frame_surface->pitch));
278 auto *pixel = row + (static_cast<std::size_t>(x) * 4U);
279 pixel[0] = static_cast<std::uint8_t>((static_cast<std::uint16_t>(mxvk::color_r(color)) * intensity) >> 8U);
280 pixel[1] = static_cast<std::uint8_t>((static_cast<std::uint16_t>(mxvk::color_g(color)) * intensity) >> 8U);
281 pixel[2] = static_cast<std::uint8_t>((static_cast<std::uint16_t>(mxvk::color_b(color)) * intensity) >> 8U);
282 pixel[3] = mxvk::color_a(color);
283 }
284
285 void draw_textured_triangle(const TexVertex &a, const TexVertex &b, const TexVertex &c, float intensity) {
286 if (texture.width <= 0 || texture.height <= 0 || texture.pixels.empty()) {
287 return;
288 }
289
290 const mxvk::vec2D p0(a.position.x, a.position.y);
291 const mxvk::vec2D p1(b.position.x, b.position.y);
292 const mxvk::vec2D p2(c.position.x, c.position.y);
293 const float area = mxvk::edge_function(p0, p1, p2);
294 if (std::fabs(area) <= mxvk::EPSILON) {
295 return;
296 }
297 const bool positive_area = area > 0.0f;
298
299 const int min_x = std::max(0, static_cast<int>(std::floor(std::min({p0.x, p1.x, p2.x}))));
300 const int max_x = std::min(frame_width - 1, static_cast<int>(std::ceil(std::max({p0.x, p1.x, p2.x}))));
301 const int min_y = std::max(0, static_cast<int>(std::floor(std::min({p0.y, p1.y, p2.y}))));
302 const int max_y = std::min(frame_height - 1, static_cast<int>(std::ceil(std::max({p0.y, p1.y, p2.y}))));
303
304 if (min_x > max_x || min_y > max_y) {
305 return;
306 }
307
308 const float inv_area = 1.0f / area;
309 const float inv_z0 = 1.0f / std::max(a.depth, 0.001f);
310 const float inv_z1 = 1.0f / std::max(b.depth, 0.001f);
311 const float inv_z2 = 1.0f / std::max(c.depth, 0.001f);
312 const float u_over_z0 = a.uv.x * inv_z0;
313 const float u_over_z1 = b.uv.x * inv_z1;
314 const float u_over_z2 = c.uv.x * inv_z2;
315 const float v_over_z0 = a.uv.y * inv_z0;
316 const float v_over_z1 = b.uv.y * inv_z1;
317 const float v_over_z2 = c.uv.y * inv_z2;
318 const std::uint16_t fixed_intensity = static_cast<std::uint16_t>(std::clamp(intensity, 0.0f, 1.0f) * 256.0f);
319
320 const float w0_dx = p2.y - p1.y;
321 const float w0_dy = -(p2.x - p1.x);
322 const float w1_dx = p0.y - p2.y;
323 const float w1_dy = -(p0.x - p2.x);
324 const float w2_dx = p1.y - p0.y;
325 const float w2_dy = -(p1.x - p0.x);
326
327 const mxvk::vec2D row_start(static_cast<float>(min_x) + 0.5f, static_cast<float>(min_y) + 0.5f);
328 float row_w0 = mxvk::edge_function(p1, p2, row_start);
329 float row_w1 = mxvk::edge_function(p2, p0, row_start);
330 float row_w2 = mxvk::edge_function(p0, p1, row_start);
331 float row_inv_z = ((row_w0 * inv_z0) + (row_w1 * inv_z1) + (row_w2 * inv_z2)) * inv_area;
332 float row_u_over_z = ((row_w0 * u_over_z0) + (row_w1 * u_over_z1) + (row_w2 * u_over_z2)) * inv_area;
333 float row_v_over_z = ((row_w0 * v_over_z0) + (row_w1 * v_over_z1) + (row_w2 * v_over_z2)) * inv_area;
334
335 const float inv_z_dx = ((w0_dx * inv_z0) + (w1_dx * inv_z1) + (w2_dx * inv_z2)) * inv_area;
336 const float inv_z_dy = ((w0_dy * inv_z0) + (w1_dy * inv_z1) + (w2_dy * inv_z2)) * inv_area;
337 const float u_over_z_dx = ((w0_dx * u_over_z0) + (w1_dx * u_over_z1) + (w2_dx * u_over_z2)) * inv_area;
338 const float u_over_z_dy = ((w0_dy * u_over_z0) + (w1_dy * u_over_z1) + (w2_dy * u_over_z2)) * inv_area;
339 const float v_over_z_dx = ((w0_dx * v_over_z0) + (w1_dx * v_over_z1) + (w2_dx * v_over_z2)) * inv_area;
340 const float v_over_z_dy = ((w0_dy * v_over_z0) + (w1_dy * v_over_z1) + (w2_dy * v_over_z2)) * inv_area;
341
342 for (int y = min_y; y <= max_y; ++y) {
343 float w0 = row_w0;
344 float w1 = row_w1;
345 float w2 = row_w2;
346 float inv_z = row_inv_z;
347 float u_over_z = row_u_over_z;
348 float v_over_z = row_v_over_z;
349
350 for (int x = min_x; x <= max_x; ++x) {
351 if ((positive_area && w0 >= 0.0f && w1 >= 0.0f && w2 >= 0.0f) || (!positive_area && w0 <= 0.0f && w1 <= 0.0f && w2 <= 0.0f)) {
352 if (std::fabs(inv_z) > mxvk::EPSILON) {
353 const float reciprocal_z = 1.0f / inv_z;
354 const float u = u_over_z * reciprocal_z;
355 const float v = v_over_z * reciprocal_z;
356 put_shaded_pixel_unchecked(x, y, texture.sample_nearest(u, v), fixed_intensity);
357 }
358 }
359
360 w0 += w0_dx;
361 w1 += w1_dx;
362 w2 += w2_dx;
363 inv_z += inv_z_dx;
364 u_over_z += u_over_z_dx;
365 v_over_z += v_over_z_dx;
366 }
367
368 row_w0 += w0_dy;
369 row_w1 += w1_dy;
370 row_w2 += w2_dy;
371 row_inv_z += inv_z_dy;
372 row_u_over_z += u_over_z_dy;
373 row_v_over_z += v_over_z_dy;
374 }
375 }
376
377 static mxvk::vec4D project_to_screen(const mxvk::vec4D &point, int width, int height) {
378 const float scale = static_cast<float>(std::min(width, height)) * 0.52f;
379 const float center_x = static_cast<float>(width) * 0.5f;
380 const float center_y = static_cast<float>(height) * 0.5f;
381 const float z = std::max(point.z, 0.001f);
382 return {center_x + (point.x / z) * scale, center_y - (point.y / z) * scale, point.z, 1.0f};
383 }
384 };
385} // namespace example
386
387int main(int argc, char **argv) {
388 try {
389 Arguments args = proc_args(argc, argv);
390 example::Math3DTextureWindow window(args, "MXVK 3D Math Texture");
391 window.loop();
392 } catch (mxvk::Exception &e) {
393 std::cerr << std::format("mxvk: Exception: {}\n", e.text());
394 return EXIT_FAILURE;
395 } catch (ArgException<std::string> &e) {
396 std::cerr << std::format("mxvk: Argument Exception: {}\n", e.text());
397 return EXIT_FAILURE;
398 }
399 return EXIT_SUCCESS;
400}
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:854
Exception thrown by Argz::proc() on unrecognised or malformed options.
Definition argz.hpp:169
void operator()(SDL_Surface *surface) const
Definition main.cpp:27
void event(SDL_Event &e) override
Handle one SDL event.
Definition main.cpp:146
Math3DTextureWindow(const Arguments &args, const std::string &title)
Definition main.cpp:141
void proc() override
Execute one processing/update step.
Definition main.cpp:156
std::string text() const
Four-by-four homogeneous transform matrix.
Definition mxvk_math.h:706
void BuildXYZ(float theta_x, float theta_y, float theta_z)
Build an XYZ Euler rotation matrix from angles in degrees.
Definition mxvk_math.h:859
vec4D MulVec(const vec4D &in) const
Transform a homogeneous 4D vector by this matrix.
Definition mxvk_math.h:771
Main Vulkan window wrapper for MXVK.
Definition mxvk.hpp:39
void loop()
Run the main event/render loop.
Definition mxvk.cpp:651
VK_Sprite * createSprite(const std::string &pngPath, const std::string &vertexShaderPath="", const std::string &fragmentShaderPath="")
Create a sprite from a PNG file and register it with this window.
Definition mxvk.cpp:4455
VkExtent2D swapchain_extent
Definition mxvk.hpp:616
void setClearColor(float r, float g, float b, float a=1.0f)
Set the per-frame color attachment clear color.
Definition mxvk.cpp:637
void exit()
Request loop termination.
Definition mxvk.cpp:1378
VK_Window()=default
Construct an empty window object.
Two-dimensional float vector with common arithmetic helpers.
Definition mxvk_math.h:158
Three-dimensional float vector with arithmetic, dot, and cross-product helpers.
Definition mxvk_math.h:256
float z
Z coordinate.
Definition mxvk_math.h:265
float x
X coordinate.
Definition mxvk_math.h:259
void Normalize()
Normalize this vector in place, or reset it to zero if it is too short.
Definition mxvk_math.h:327
float y
Y coordinate.
Definition mxvk_math.h:262
Four-dimensional float vector used for homogeneous 3D coordinates.
Definition mxvk_math.h:363
float y
Y coordinate.
Definition mxvk_math.h:369
float x
X coordinate.
Definition mxvk_math.h:366
float z
Z coordinate.
Definition mxvk_math.h:372
void Build(const vec4D &to)
Replace this vector with the direction from this point to to.
Definition mxvk_math.h:473
#define MXVK_VALIDATION
Definition mxvk.hpp:28
Math, geometry, rasterization, and simple software 3D pipeline helpers for MXVK examples.
PNG image loading and saving utilities via SDL3.
std::unique_ptr< SDL_Surface, SurfaceDeleter > SurfacePtr
Definition main.cpp:27
std::string resolve_texture_path(const Arguments &args)
Definition main.cpp:78
std::filesystem::path texture_path(const std::string &filename, const std::string &asset_path)
Definition main.cpp:122
Texture load_texture(const std::string &filename, const std::string &asset_path, bool generate_mipmaps)
Definition main.cpp:135
int main()
Definition main.py:165
Utilities for loading and saving PNG images.
Definition mxvk.hpp:31
constexpr std::uint8_t color_r(MXCOLOR color)
Extract the red component from a packed ARGB color.
Definition mxvk_math.h:52
std::uint32_t MXCOLOR
Packed 32-bit color in ARGB byte order.
Definition mxvk_math.h:40
void BuildTables()
Rebuild the sine and cosine lookup tables.
Definition mxvk_math.h:98
SDL_Surface * LoadPNG(const char *file)
Load a PNG file into an SDL_Surface.
Definition mxvk_png.cpp:89
constexpr std::uint8_t color_g(MXCOLOR color)
Extract the green component from a packed ARGB color.
Definition mxvk_math.h:55
constexpr MXCOLOR MXVK_RGB(int r, int g, int b)
Build an opaque ARGB color from red, green, and blue components.
Definition mxvk_math.h:49
constexpr std::uint8_t color_a(MXCOLOR color)
Extract the alpha component from a packed ARGB color.
Definition mxvk_math.h:61
float edge_function(const vec2D &a, const vec2D &b, const vec2D &p)
Compute the signed edge function value for point p relative to edge a-b.
Definition mxvk_math.h:1972
constexpr float EPSILON
Default tolerance used for floating-point singularity and zero-length checks.
Definition mxvk_math.h:37
constexpr std::uint8_t color_b(MXCOLOR color)
Extract the blue component from a packed ARGB color.
Definition mxvk_math.h:58
Plain data structure returned by proc_args() with all common libmx2 CLI options.
Definition argz.hpp:718
std::string texture
Optional texture file path (--texture).
Definition argz.hpp:752
std::string filename
Optional input filename (--filename).
Definition argz.hpp:726
std::string path
Asset root; proc_args() defaults it to the executable directory.
Definition argz.hpp:723
mxvk::MXCOLOR sample(float u, float v) const
Definition main.cpp:45
std::vector< mxvk::MXCOLOR > pixels
Definition main.cpp:191
mxvk::MXCOLOR sample_nearest(float u, float v) const
Definition main.cpp:57