From 824efcc71fea0f210e1f93efb9431aaa78ab27f3 Mon Sep 17 00:00:00 2001 From: frank Date: Sat, 3 Jun 2023 01:07:18 -0400 Subject: [PATCH] add external resources; add alpha to plane colors --- README.md | 9 +++++++++ src/Attributes.cpp | 6 ------ src/Attributes.hpp | 20 ++++++++++++++++++-- src/Model.hpp | 4 ++-- src/Text.hpp | 2 +- src/math.cpp | 2 +- src/math.hpp | 2 +- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 494a050..dbc89d1 100644 --- a/README.md +++ b/README.md @@ -449,6 +449,15 @@ To build a WASM library that can be used to build an Emscripten version of a SPA There is a detailed tutorial on using Zbar with WebAssembly at https://barkeywolf.consulting/posts/barcode-scanner-webassembly/ +External Resources +------------------ + +* [Khronos's OpenGL and GLSL wiki](https://www.khronos.org/opengl/wiki/Main_Page) +* [docs.gl: official OpenGL API documentation with added features](https://docs.gl) +* [MDN's list of best practices for WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices) +* [Emscripten documentation's chapter on optimizing for WebGL](https://emscripten.org/docs/optimizing/Optimizing-WebGL.html) +* [SDL wiki](https://wiki.libsdl.org) + Font ---- diff --git a/src/Attributes.cpp b/src/Attributes.cpp index 4ebfbb4..e7130f6 100644 --- a/src/Attributes.cpp +++ b/src/Attributes.cpp @@ -190,10 +190,6 @@ sb::Attributes::operator int() const return index(); } -/* Extend to include these attributes at the end. The argument will be automatically converted to an - * Attributes object, so the vertices can be in any of the Attributes constructor formats. If no attributes - * have been constructed or initialized, the current vertices will be set to these vertices. Otherwise, - * vertices will be inserted at the end of the current vertices. */ void sb::Attributes::add(const Attributes& other) { /* If the variant is std::monostate, these are the first attributes, so set vertices to these */ @@ -236,8 +232,6 @@ void sb::Attributes::add(const Attributes& other) } } -/* Add attributes to the end count number of times. If count is 1, this has the same effect as the - * add function. */ void sb::Attributes::extend(const Attributes& other, std::size_t count) { while (count--) diff --git a/src/Attributes.hpp b/src/Attributes.hpp index 9748c9c..ac9ddf5 100644 --- a/src/Attributes.hpp +++ b/src/Attributes.hpp @@ -210,7 +210,15 @@ namespace sb } } - void add(const Attributes&); + /*! + * Extend to include these attributes at the end. The argument will be automatically converted to an + * Attributes object, so the vertices can be in any of the Attributes constructor formats. If no attributes + * have been constructed or initialized, the current vertices will be set to these vertices. Otherwise, + * vertices will be inserted at the end of the current vertices. + * + * @param other attributes to add + */ + void add(const Attributes& other); /*! * Add a 2D, 3D or 4D vertex by specifying each coordinate as a separate argument. All arguments must have @@ -270,7 +278,15 @@ namespace sb return std::get>(vertices); } - void extend(const Attributes&, std::size_t = 1); + /*! + * Repeatedly add attributes to the end count number of times. If count is 1, this has the same effect as the + * add function. + * + * @param other attributes to add repeatedly + * @param count number of times to repeat + */ + void extend(const Attributes& other, std::size_t count = 1); + void index(GLint); GLint index() const; diff --git a/src/Model.hpp b/src/Model.hpp index ce27f9e..dfd1b49 100644 --- a/src/Model.hpp +++ b/src/Model.hpp @@ -144,8 +144,8 @@ namespace sb /* A gradient from magenta to yellow */ inline const static std::shared_ptr color = std::make_shared(sb::Attributes{ - {1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {0.8f, 0.0f, 0.3f}, - {1.0f, 1.0f, 0.0f}, {0.8f, 0.0f, 0.3f}, {0.8f, 0.0f, 0.3f} + {1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f, 1.0f}, {0.8f, 0.0f, 0.3f, 1.0f}, + {1.0f, 1.0f, 0.0f, 1.0f}, {0.8f, 0.0f, 0.3f, 1.0f}, {0.8f, 0.0f, 0.3f, 1.0f} }); Plane() : Model(std::map>({{"position", position}, {"uv", uv}, {"color", color}})) {} diff --git a/src/Text.hpp b/src/Text.hpp index 9db778c..839c15a 100644 --- a/src/Text.hpp +++ b/src/Text.hpp @@ -1,6 +1,6 @@ #include "SDL.h" #include "SDL_ttf.h" -#include "SDL2_rotozoom.h" +#include "sdl2-gfx/SDL2_rotozoom.h" #include "Model.hpp" #include "Color.hpp" diff --git a/src/math.cpp b/src/math.cpp index 40093dc..a113c28 100644 --- a/src/math.cpp +++ b/src/math.cpp @@ -35,7 +35,7 @@ float sb::angle_ratio(float start, float end) return sb::angle_difference(start, end) / glm::pi(); } -std::vector sb::bezier(const std::vector control, int resolution) +std::vector sb::bezier(const std::vector& control, int resolution) { std::vector points; points.reserve(resolution); diff --git a/src/math.hpp b/src/math.hpp index 7f34d5f..e25e3d6 100644 --- a/src/math.hpp +++ b/src/math.hpp @@ -112,5 +112,5 @@ namespace sb * @param vertices four 2D control points * @param resolution number of points that will be in the computed curve */ - std::vector bezier(const std::vector vertices, int resolution = 30); + std::vector bezier(const std::vector& vertices, int resolution = 30); }