Browse Source

Changed demos to use types not structs

shared-context
Mikko Mononen 10 years ago
parent
commit
8519f09569
9 changed files with 81 additions and 78 deletions
  1. +40
    -40
      example/demo.c
  2. +4
    -3
      example/demo.h
  3. +7
    -7
      example/example_fbo.c
  4. +3
    -3
      example/example_gl2.c
  5. +4
    -4
      example/example_gl3.c
  6. +3
    -3
      example/example_gles2.c
  7. +3
    -3
      example/example_gles3.c
  8. +8
    -8
      example/perf.c
  9. +9
    -7
      example/perf.h

+ 40
- 40
example/demo.c View File

@@ -30,7 +30,7 @@ static float maxf(float a, float b) { return a > b ? a : b; }
static float clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); }

// Returns 1 if col.rgba is 0.0f,0.0f,0.0f,0.0f, 0 otherwise
int isBlack( struct NVGcolor col )
int isBlack(NVGcolor col)
{
if( col.r == 0.0f && col.g == 0.0f && col.b == 0.0f && col.a == 0.0f )
{
@@ -61,11 +61,11 @@ static char* cpToUTF8(int cp, char* str)
}


void drawWindow(struct NVGcontext* vg, const char* title, float x, float y, float w, float h)
void drawWindow(NVGcontext* vg, const char* title, float x, float y, float w, float h)
{
float cornerRadius = 3.0f;
struct NVGpaint shadowPaint;
struct NVGpaint headerPaint;
NVGpaint shadowPaint;
NVGpaint headerPaint;

nvgSave(vg);
// nvgClearState(vg);
@@ -113,9 +113,9 @@ void drawWindow(struct NVGcontext* vg, const char* title, float x, float y, floa
nvgRestore(vg);
}

void drawSearchBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
void drawSearchBox(NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
struct NVGpaint bg;
NVGpaint bg;
char icon[8];
float cornerRadius = h/2-1;

@@ -151,9 +151,9 @@ void drawSearchBox(struct NVGcontext* vg, const char* text, float x, float y, fl
nvgText(vg, x+w-h*0.55f, y+h*0.55f, cpToUTF8(ICON_CIRCLED_CROSS,icon), NULL);
}

void drawDropDown(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
void drawDropDown(NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
struct NVGpaint bg;
NVGpaint bg;
char icon[8];
float cornerRadius = 4.0f;

@@ -181,7 +181,7 @@ void drawDropDown(struct NVGcontext* vg, const char* text, float x, float y, flo
nvgText(vg, x+w-h*0.5f, y+h*0.5f, cpToUTF8(ICON_CHEVRON_RIGHT,icon), NULL);
}

void drawLabel(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
void drawLabel(NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
NVG_NOTUSED(w);

@@ -193,9 +193,9 @@ void drawLabel(struct NVGcontext* vg, const char* text, float x, float y, float
nvgText(vg, x,y+h*0.5f,text, NULL);
}

void drawEditBoxBase(struct NVGcontext* vg, float x, float y, float w, float h)
void drawEditBoxBase(NVGcontext* vg, float x, float y, float w, float h)
{
struct NVGpaint bg;
NVGpaint bg;
// Edit
bg = nvgBoxGradient(vg, x+1,y+1+1.5f, w-2,h-2, 3,4, nvgRGBA(255,255,255,32), nvgRGBA(32,32,32,32));
nvgBeginPath(vg);
@@ -209,7 +209,7 @@ void drawEditBoxBase(struct NVGcontext* vg, float x, float y, float w, float h)
nvgStroke(vg);
}

void drawEditBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
void drawEditBox(NVGcontext* vg, const char* text, float x, float y, float w, float h)
{

drawEditBoxBase(vg, x,y, w,h);
@@ -221,7 +221,7 @@ void drawEditBox(struct NVGcontext* vg, const char* text, float x, float y, floa
nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL);
}

void drawEditBoxNum(struct NVGcontext* vg,
void drawEditBoxNum(NVGcontext* vg,
const char* text, const char* units, float x, float y, float w, float h)
{
float uw;
@@ -243,9 +243,9 @@ void drawEditBoxNum(struct NVGcontext* vg,
nvgText(vg, x+w-uw-h*0.5f,y+h*0.5f,text, NULL);
}

void drawCheckBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
void drawCheckBox(NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
struct NVGpaint bg;
NVGpaint bg;
char icon[8];
NVG_NOTUSED(w);

@@ -269,9 +269,9 @@ void drawCheckBox(struct NVGcontext* vg, const char* text, float x, float y, flo
nvgText(vg, x+9+2, y+h*0.5f, cpToUTF8(ICON_CHECK,icon), NULL);
}

void drawButton(struct NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, struct NVGcolor col)
void drawButton(NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, NVGcolor col)
{
struct NVGpaint bg;
NVGpaint bg;
char icon[8];
float cornerRadius = 4.0f;
float tw = 0, iw = 0;
@@ -318,9 +318,9 @@ void drawButton(struct NVGcontext* vg, int preicon, const char* text, float x, f
nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL);
}

void drawSlider(struct NVGcontext* vg, float pos, float x, float y, float w, float h)
void drawSlider(NVGcontext* vg, float pos, float x, float y, float w, float h)
{
struct NVGpaint bg, knob;
NVGpaint bg, knob;
float cy = y+(int)(h*0.5f);
float kr = (int)(h*0.25f);

@@ -360,9 +360,9 @@ void drawSlider(struct NVGcontext* vg, float pos, float x, float y, float w, flo
nvgRestore(vg);
}

void drawEyes(struct NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t)
void drawEyes(NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t)
{
struct NVGpaint gloss, bg;
NVGpaint gloss, bg;
float ex = w *0.23f;
float ey = h * 0.5f;
float lx = x + ex;
@@ -426,9 +426,9 @@ void drawEyes(struct NVGcontext* vg, float x, float y, float w, float h, float m
nvgFill(vg);
}

void drawGraph(struct NVGcontext* vg, float x, float y, float w, float h, float t)
void drawGraph(NVGcontext* vg, float x, float y, float w, float h, float t)
{
struct NVGpaint bg;
NVGpaint bg;
float samples[6];
float sx[6], sy[6];
float dx = w/5.0f;
@@ -497,14 +497,14 @@ void drawGraph(struct NVGcontext* vg, float x, float y, float w, float h, float
nvgStrokeWidth(vg, 1.0f);
}

void drawSpinner(struct NVGcontext* vg, float cx, float cy, float r, float t)
void drawSpinner(NVGcontext* vg, float cx, float cy, float r, float t)
{
float a0 = 0.0f + t*6;
float a1 = NVG_PI + t*6;
float r0 = r;
float r1 = r * 0.75f;
float ax,ay, bx,by;
struct NVGpaint paint;
NVGpaint paint;

nvgSave(vg);

@@ -523,10 +523,10 @@ void drawSpinner(struct NVGcontext* vg, float cx, float cy, float r, float t)
nvgRestore(vg);
}

void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, const int* images, int nimages, float t)
void drawThumbnails(NVGcontext* vg, float x, float y, float w, float h, const int* images, int nimages, float t)
{
float cornerRadius = 3.0f;
struct NVGpaint shadowPaint, imgPaint, fadePaint;
NVGpaint shadowPaint, imgPaint, fadePaint;
float ix,iy,iw,ih;
float thumb = 60.0f;
float arry = 30.5f;
@@ -643,12 +643,12 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c
nvgRestore(vg);
}

void drawColorwheel(struct NVGcontext* vg, float x, float y, float w, float h, float t)
void drawColorwheel(NVGcontext* vg, float x, float y, float w, float h, float t)
{
int i;
float r0, r1, ax,ay, bx,by, cx,cy, aeps, r;
float hue = sinf(t * 0.12f);
struct NVGpaint paint;
NVGpaint paint;

nvgSave(vg);

@@ -748,7 +748,7 @@ void drawColorwheel(struct NVGcontext* vg, float x, float y, float w, float h, f
nvgRestore(vg);
}

void drawLines(struct NVGcontext* vg, float x, float y, float w, float h, float t)
void drawLines(NVGcontext* vg, float x, float y, float w, float h, float t)
{
int i, j;
float pad = 5.0f, s = w/9.0f - pad*2;
@@ -802,7 +802,7 @@ void drawLines(struct NVGcontext* vg, float x, float y, float w, float h, float
nvgRestore(vg);
}

int loadDemoData(struct NVGcontext* vg, struct DemoData* data)
int loadDemoData(NVGcontext* vg, DemoData* data)
{
int i;

@@ -838,7 +838,7 @@ int loadDemoData(struct NVGcontext* vg, struct DemoData* data)
return 0;
}

void freeDemoData(struct NVGcontext* vg, struct DemoData* data)
void freeDemoData(NVGcontext* vg, DemoData* data)
{
int i;

@@ -849,10 +849,10 @@ void freeDemoData(struct NVGcontext* vg, struct DemoData* data)
nvgDeleteImage(vg, data->images[i]);
}

void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float height, float mx, float my)
void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, float mx, float my)
{
struct NVGtextRow rows[3];
struct NVGglyphPosition glyphs[100];
NVGtextRow rows[3];
NVGglyphPosition glyphs[100];
const char* text = "This is longer chunk of text.\n \n Would have used lorem ipsum but she was busy jumping over the lazy dog with the fox and all the men who came to the aid of the party.";
const char* start;
const char* end;
@@ -879,7 +879,7 @@ void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float h
end = text + strlen(text);
while ((nrows = nvgTextBreakLines(vg, start, end, width, rows, 3))) {
for (i = 0; i < nrows; i++) {
struct NVGtextRow* row = &rows[i];
NVGtextRow* row = &rows[i];
int hit = mx > x && mx < (x+width) && my >= y && my < (y+lineh);

nvgBeginPath(vg);
@@ -965,7 +965,7 @@ void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float h
nvgRestore(vg);
}

void drawWidths(struct NVGcontext* vg, float x, float y, float width)
void drawWidths(NVGcontext* vg, float x, float y, float width)
{
int i;

@@ -986,7 +986,7 @@ void drawWidths(struct NVGcontext* vg, float x, float y, float width)
nvgRestore(vg);
}

void drawCaps(struct NVGcontext* vg, float x, float y, float width)
void drawCaps(NVGcontext* vg, float x, float y, float width)
{
int i;
int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE};
@@ -1017,8 +1017,8 @@ void drawCaps(struct NVGcontext* vg, float x, float y, float width)
nvgRestore(vg);
}

void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height,
float t, int blowup, struct DemoData* data)
void renderDemo(NVGcontext* vg, float mx, float my, float width, float height,
float t, int blowup, DemoData* data)
{
float x,y,popy;



+ 4
- 3
example/demo.h View File

@@ -11,10 +11,11 @@ struct DemoData {
int fontNormal, fontBold, fontIcons;
int images[12];
};
typedef struct DemoData DemoData;

int loadDemoData(struct NVGcontext* vg, struct DemoData* data);
void freeDemoData(struct NVGcontext* vg, struct DemoData* data);
void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height, float t, int blowup, struct DemoData* data);
int loadDemoData(NVGcontext* vg, DemoData* data);
void freeDemoData(NVGcontext* vg, DemoData* data);
void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, float t, int blowup, DemoData* data);

void saveScreenShot(int w, int h, int premult, const char* name);



+ 7
- 7
example/example_fbo.c View File

@@ -30,7 +30,7 @@
#include "nanovg_gl_utils.h"
#include "perf.h"

void renderPattern(struct NVGcontext* vg, struct NVGLUframebuffer* fb, float t, float pxRatio)
void renderPattern(NVGcontext* vg, NVGLUframebuffer* fb, float t, float pxRatio)
{
int winWidth, winHeight;
int fboWidth, fboHeight;
@@ -70,7 +70,7 @@ void renderPattern(struct NVGcontext* vg, struct NVGLUframebuffer* fb, float t,
nvgluBindFramebuffer(NULL);
}

int loadFonts(struct NVGcontext* vg)
int loadFonts(NVGcontext* vg)
{
int font;
font = nvgCreateFont(vg, "sans", "../example/Roboto-Regular.ttf");
@@ -102,11 +102,11 @@ static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
int main()
{
GLFWwindow* window;
struct NVGcontext* vg = NULL;
struct GPUtimer gpuTimer;
struct PerfGraph fps, cpuGraph, gpuGraph;
NVGcontext* vg = NULL;
GPUtimer gpuTimer;
PerfGraph fps, cpuGraph, gpuGraph;
double prevt = 0, cpuTime = 0;
struct NVGLUframebuffer* fb = NULL;
NVGLUframebuffer* fb = NULL;
int winWidth, winHeight;
int fbWidth, fbHeight;
float pxRatio;
@@ -215,7 +215,7 @@ int main()

// Use the FBO as image pattern.
if (fb != NULL) {
struct NVGpaint img = nvgImagePattern(vg, 0, 0, 100, 100, 0, fb->image, NVG_REPEATX|NVG_REPEATY, 1.0f);
NVGpaint img = nvgImagePattern(vg, 0, 0, 100, 100, 0, fb->image, NVG_REPEATX|NVG_REPEATY, 1.0f);
nvgSave(vg);

for (i = 0; i < 20; i++) {


+ 3
- 3
example/example_gl2.c View File

@@ -54,9 +54,9 @@ static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
int main()
{
GLFWwindow* window;
struct DemoData data;
struct NVGcontext* vg = NULL;
struct PerfGraph fps;
DemoData data;
NVGcontext* vg = NULL;
PerfGraph fps;
double prevt = 0;

if (!glfwInit()) {


+ 4
- 4
example/example_gl3.c View File

@@ -57,10 +57,10 @@ static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
int main()
{
GLFWwindow* window;
struct DemoData data;
struct NVGcontext* vg = NULL;
struct GPUtimer gpuTimer;
struct PerfGraph fps, cpuGraph, gpuGraph;
DemoData data;
NVGcontext* vg = NULL;
GPUtimer gpuTimer;
PerfGraph fps, cpuGraph, gpuGraph;
double prevt = 0, cpuTime = 0;

if (!glfwInit()) {


+ 3
- 3
example/example_gles2.c View File

@@ -53,9 +53,9 @@ static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
int main()
{
GLFWwindow* window;
struct DemoData data;
struct NVGcontext* vg = NULL;
struct PerfGraph fps;
DemoData data;
NVGcontext* vg = NULL;
PerfGraph fps;
double prevt = 0;

if (!glfwInit()) {


+ 3
- 3
example/example_gles3.c View File

@@ -53,9 +53,9 @@ static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
int main()
{
GLFWwindow* window;
struct DemoData data;
struct NVGcontext* vg = NULL;
struct PerfGraph fps;
DemoData data;
NVGcontext* vg = NULL;
PerfGraph fps;
double prevt = 0;

if (!glfwInit()) {


+ 8
- 8
example/perf.c View File

@@ -21,7 +21,7 @@
//pfnGLGETQUERYOBJECTUI64V glGetQueryObjectui64v = 0;
#endif

void initGPUTimer(struct GPUtimer* timer)
void initGPUTimer(GPUtimer* timer)
{
memset(timer, 0, sizeof(*timer));

@@ -39,7 +39,7 @@ void initGPUTimer(struct GPUtimer* timer)
}*/
}

void startGPUTimer(struct GPUtimer* timer)
void startGPUTimer(GPUtimer* timer)
{
if (!timer->supported)
return;
@@ -47,7 +47,7 @@ void startGPUTimer(struct GPUtimer* timer)
timer->cur++;
}

int stopGPUTimer(struct GPUtimer* timer, float* times, int maxTimes)
int stopGPUTimer(GPUtimer* timer, float* times, int maxTimes)
{
NVG_NOTUSED(times);
NVG_NOTUSED(maxTimes);
@@ -74,21 +74,21 @@ int stopGPUTimer(struct GPUtimer* timer, float* times, int maxTimes)
}


void initGraph(struct PerfGraph* fps, int style, const char* name)
void initGraph(PerfGraph* fps, int style, const char* name)
{
memset(fps, 0, sizeof(struct PerfGraph));
memset(fps, 0, sizeof(PerfGraph));
fps->style = style;
strncpy(fps->name, name, sizeof(fps->name));
fps->name[sizeof(fps->name)-1] = '\0';
}

void updateGraph(struct PerfGraph* fps, float frameTime)
void updateGraph(PerfGraph* fps, float frameTime)
{
fps->head = (fps->head+1) % GRAPH_HISTORY_COUNT;
fps->values[fps->head] = frameTime;
}

float getGraphAverage(struct PerfGraph* fps)
float getGraphAverage(PerfGraph* fps)
{
int i;
float avg = 0;
@@ -98,7 +98,7 @@ float getGraphAverage(struct PerfGraph* fps)
return avg / (float)GRAPH_HISTORY_COUNT;
}

void renderGraph(struct NVGcontext* vg, float x, float y, struct PerfGraph* fps)
void renderGraph(NVGcontext* vg, float x, float y, PerfGraph* fps)
{
int i;
float avg, w, h;


+ 9
- 7
example/perf.h View File

@@ -19,11 +19,12 @@ struct PerfGraph {
float values[GRAPH_HISTORY_COUNT];
int head;
};
typedef struct PerfGraph PerfGraph;

void initGraph(struct PerfGraph* fps, int style, const char* name);
void updateGraph(struct PerfGraph* fps, float frameTime);
void renderGraph(struct NVGcontext* vg, float x, float y, struct PerfGraph* fps);
float getGraphAverage(struct PerfGraph* fps);
void initGraph(PerfGraph* fps, int style, const char* name);
void updateGraph(PerfGraph* fps, float frameTime);
void renderGraph(NVGcontext* vg, float x, float y, PerfGraph* fps);
float getGraphAverage(PerfGraph* fps);

#define GPU_QUERY_COUNT 5
struct GPUtimer {
@@ -31,10 +32,11 @@ struct GPUtimer {
int cur, ret;
unsigned int queries[GPU_QUERY_COUNT];
};
typedef struct GPUtimer GPUtimer;

void initGPUTimer(struct GPUtimer* timer);
void startGPUTimer(struct GPUtimer* timer);
int stopGPUTimer(struct GPUtimer* timer, float* times, int maxTimes);
void initGPUTimer(GPUtimer* timer);
void startGPUTimer(GPUtimer* timer);
int stopGPUTimer(GPUtimer* timer, float* times, int maxTimes);

#ifdef __cplusplus
}


Loading…
Cancel
Save