Skip to content

Instantly share code, notes, and snippets.

@vurtun
Last active May 24, 2020 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vurtun/dc6a89c898d09aa31bcd934a0e952284 to your computer and use it in GitHub Desktop.
Save vurtun/dc6a89c898d09aa31bcd934a0e952284 to your computer and use it in GitHub Desktop.
stupid c++
#if 0
#include <stdio.h>
int main(void)
{
int n, t[3] = {0};
for (n = 0; n < 100; ++n) {
pytriples(t);
printf("(%d,%d,%d)\n", t[0], t[1], t[2]);
} return 0;
}
#endif
static void
pytriples(int *t)
{
do if (t[1] <= t[2])
t[1] = t[1] + 1;
else if (t[0] <= t[2])
t[0] = t[1] = t[0] + 1;
else t[2] += t[0] = t[1] = 1;
while (t[0]*t[0] + t[1]*t[1] != t[2]*t[2]);
}
static int
atlas_stitch(struct img_atlas* atl, struct arena *a,
const struct img* imgs, int img_cnt)
{
// calculate total atlas image width and max height
int w = 0, h = 0;
for (int i = 0; i < img_cnt; ++i) {
h = max(h, imgs[i].h);
w += imgs[i].w;
}
// allocate atlas
struct img_info {int xoff, w, h;};
struct img_info *img_infos = arena_alloc(a, sizeof(struct img_info) * img_cnt);
unsigned *data = arena_alloc(a, w * h * 4);
// fill atlas with images
int xoff = 0;
for (int i = 0; i < img_cnt; ++i) {
img_infos[i] = (struct img_info){xoff, imgs[i].w, imgs[i].h};
for (int y = 0; y < imgs[i].h; ++y) {
for (int x = 0; x < imgs[i].w; ++x)
data[w*y+xoff+x] = imgs[i].data[imgs[i].w*y+x];
}
xoff += imgs[0].w;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment