Skip to content

Instantly share code, notes, and snippets.

static const char* fillVertShader =
#ifdef NANOVG_GLES2
"#version 100\n"
"precision highp float;\n" // CHANGED
#endif
"uniform vec2 viewSize;\n"
"attribute vec2 vertex;\n"
"attribute vec2 tcoord;\n"
"attribute vec4 color;\n"
"varying vec2 ftcoord;\n"
@memononen
memononen / gist:9757759
Created March 25, 2014 09:06
var args as rect
#define mgArgs(...) mgmgArgs_(__VA_ARGS__, MG_NONE)
int mgArgs_(const char* text, ...);
int mgText_(const char* text, struct MGargs args);
// Can "cache" args for common operations, as well as merge them, or use inline.
int mgColor(float* r, float* g, float* b, float* a, struct MGargs args)
{
struct MGargs labelArgs = mgArgs(mgFontSize(LABEL_SIZE), mgSpacing(LABEL_SPACING));
@memononen
memononen / gist:9780262
Created March 26, 2014 10:15
va args for uints
#define foo(...) foo_(123, ##__VA_ARGS__, 0)
void foo_(int dummy, ...)
{
unsigned int v;
va_list list;
printf("foo ");
va_start(list, dummy);
for (v = va_arg(list, unsigned int); v != 0; v = va_arg(list, unsigned int))
printf("%d ", v);
va_end(list);
@memononen
memononen / gist:9852437
Last active August 29, 2015 13:57
Things which are hard to do with IMGUI
Anything with complex persistent UI state.
- collapsable tree view
- a sortable list view
- graph UI (movable nodes connected w/ wires)
- timeline UI (movable boxes constrained on rows)
void mmul(float* m, const float* a, const float* b)
{
for (int r = 0; r < 4; r++)
for (int c = 0; c < 4; c++)
m[r*4+c] = a[r*4+0] * b[0*4+c] + a[r*4+1] * b[1*4+c] + a[r*4+2] * b[2*4+c] + a[r*4+3] * b[3*4+c];
}
void midentity(float* m)
{
for (int i = 0; i < 4; i++)
/*
(0,0)
+..................
: image :
: :
: +----+ :
: |rect| :
: +----+ :
: :
...................
@memononen
memononen / gist:7045124
Created October 18, 2013 17:38
Disposable mode UI: combining flexbox for layout, templates for scopes and IMGUI for logic.
* Material dialog we're creating
+----------------------+
| Materials |
| __________________ |
|?(__________________)x|
|----------------------|
| /¨\ #|
|( ) Gold #|
| \_/ #|
@memononen
memononen / easing.c
Last active October 7, 2020 21:37
Cheap Fake Cubic Easing Curve
//
// Copyright (c) 2013 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
@memononen
memononen / diff.cpp
Last active November 20, 2021 19:01
O(NP) diff with backtracking
#include <stdio.h>
#include <vector>
#include <algorithm>
// Based on "An O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber and Gene Myers
struct Edit {
enum Type { Insert, Delete, Common };
Edit() = default;
Edit(Type _type, int _a, int _b, int _n) : type(_type), a(_a), b(_b), n(_n) {}
@memononen
memononen / merge.cpp
Last active December 4, 2021 19:19
3-way merge based on O(NP) Myers diff and diff3
#include <stdio.h>
#include <vector>
#include <span>
#include <algorithm>
// Based on
// "An O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber and Gene Myers
// - https://publications.mpi-cbg.de/Wu_1990_6334.pdf
// - Good article visualizing Myer's older algorithm: https://epxx.co/artigos/diff_en.html
//