Skip to content

Instantly share code, notes, and snippets.

@memononen
memononen / gist:cef31ababbfa6cde5eea
Created November 23, 2014 19:05
Drawing clipped anti-aliased graph using triangle strip
// Draws a graph using a triangle strip and simple gradient texture.
// Anti-aliasing may be off by a half a pixel.
// Works reasonable well with smooth as well as noisy data.
// The basic idea is that we draw the graph using a full height quad (or two triangles)
// per segment between two samples, and then we calculate texture coordinates
// so that 1px anti-aliasing gradient passes through the data points. The texture coordinate
// is calculated using the segment normal and one segment end point.
struct Point {
float x, y;
@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)
@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: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));
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: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 #|
| \_/ #|