From fbdc947802bdf2cc945a3dc5b272ebb865daac4b Mon Sep 17 00:00:00 2001 From: Caleb Gingles Date: Tue, 18 Feb 2014 16:53:48 -0500 Subject: [PATCH] Improve VC support --- example/demo.c | 3 ++- example/perf.c | 10 ++++++---- src/nanovg_gl2.h | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/example/demo.c b/example/demo.c index 63d8a86..951b281 100644 --- a/example/demo.c +++ b/example/demo.c @@ -491,6 +491,7 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c float stackh = (nimages/2) * (thumb+10) + 10; int i; float u = (1+cosf(t*0.5f))*0.5f; + float scrollh; nvgSave(vg); // nvgClearState(vg); @@ -578,7 +579,7 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c // nvgFillColor(vg, nvgRGBA(255,0,0,128)); nvgFill(vg); - float scrollh = (h/stackh) * (h-8); + scrollh = (h/stackh) * (h-8); shadowPaint = nvgBoxGradient(vg, x+w-12-1,y+4+(h-8-scrollh)*u-1, 8,scrollh, 3,4, nvgRGBA(220,220,220,255), nvgRGBA(128,128,128,255)); nvgBeginPath(vg); nvgRoundedRect(vg, x+w-12+1,y+4+1 + (h-8-scrollh)*u, 8-2,scrollh-2, 2); diff --git a/example/perf.c b/example/perf.c index 7ca13be..9b0780f 100644 --- a/example/perf.c +++ b/example/perf.c @@ -116,17 +116,19 @@ void renderGraph(struct NVGcontext* vg, float x, float y, struct PerfGraph* fps) if (fps->style == GRAPH_RENDER_FPS) { for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = 1.0f / (0.00001f + fps->values[(fps->head+i) % GRAPH_HISTORY_COUNT]); + float vx, vy; if (v > 80.0f) v = 80.0f; - float vx = x + ((float)i/(GRAPH_HISTORY_COUNT-1)) * w; - float vy = y + h - ((v / 80.0f) * h); + vx = x + ((float)i/(GRAPH_HISTORY_COUNT-1)) * w; + vy = y + h - ((v / 80.0f) * h); nvgLineTo(vg, vx, vy); } } else { for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = fps->values[(fps->head+i) % GRAPH_HISTORY_COUNT] * 1000.0f; + float vx, vy; if (v > 20.0f) v = 20.0f; - float vx = x + ((float)i/(GRAPH_HISTORY_COUNT-1)) * w; - float vy = y + h - ((v / 20.0f) * h); + vx = x + ((float)i/(GRAPH_HISTORY_COUNT-1)) * w; + vy = y + h - ((v / 20.0f) * h); nvgLineTo(vg, vx, vy); } } diff --git a/src/nanovg_gl2.h b/src/nanovg_gl2.h index ba0798b..cbb5acb 100644 --- a/src/nanovg_gl2.h +++ b/src/nanovg_gl2.h @@ -720,6 +720,10 @@ static void glnvg__renderFill(void* uptr, struct NVGpaint* paint, struct NVGscis glDisableVertexAttribArray(1); } else { + float quad[6*2] = { + bounds[0], bounds[3], bounds[2], bounds[3], bounds[2], bounds[1], + bounds[0], bounds[3], bounds[2], bounds[1], bounds[0], bounds[1], + }; glEnable(GL_CULL_FACE); @@ -782,10 +786,6 @@ static void glnvg__renderFill(void* uptr, struct NVGpaint* paint, struct NVGscis glDisableVertexAttribArray(1); - float quad[6*2] = { - bounds[0], bounds[3], bounds[2], bounds[3], bounds[2], bounds[1], - bounds[0], bounds[3], bounds[2], bounds[1], bounds[0], bounds[1], - }; glBufferSubData(GL_ARRAY_BUFFER, 0, 6 * 2*sizeof(float), quad); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (const GLvoid*)0); glVertexAttrib2f(1, 0.5f, 1.0f);