Browse Source

Code format

shared-context
satoren 8 years ago
parent
commit
9dbd79dbc7
2 changed files with 46 additions and 48 deletions
  1. +45
    -47
      example/demo.c
  2. +1
    -1
      src/nanovg_gl.h

+ 45
- 47
example/demo.c View File

@@ -1069,53 +1069,51 @@ void drawScissor(NVGcontext* vg, float x, float y, float t)


void drawGlobalCompositeOperation(NVGcontext* vg, float x, float y, DemoData* data) void drawGlobalCompositeOperation(NVGcontext* vg, float x, float y, DemoData* data)
{ {
int i;
NVGpaint imgPaint;
enum NVGcompositeOperation ops[] = {
NVG_SOURCE_OVER,
NVG_SOURCE_IN,
NVG_SOURCE_OUT,
NVG_ATOP,
NVG_DESTINATION_OVER,
NVG_DESTINATION_IN,
NVG_DESTINATION_OUT,
NVG_DESTINATION_ATOP,
NVG_LIGHTER,
NVG_COPY,
NVG_XOR};
int count = sizeof(ops)/sizeof(ops[0]);

for(i=0;i<count;++i)
{
nvgSave(vg);
nvgTranslate(vg, x + i * 40, y);
nvgGlobalCompositeOperation(vg, NVG_COPY);
imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_a, 1.0);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, 30, 30);
nvgFillPaint(vg, imgPaint);
nvgFill(vg);
nvgGlobalCompositeOperation(vg, ops[i]);
imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_b, 1.0);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, 30, 30);
nvgFillPaint(vg, imgPaint);
nvgFill(vg);
//fill background transparent color to white.
nvgGlobalCompositeOperation(vg, NVG_DESTINATION_OVER);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, 30, 30);
nvgFillColor(vg, nvgRGBA(255,255,255,255));
nvgFill(vg);
nvgRestore(vg);
}
int i;
NVGpaint imgPaint;
enum NVGcompositeOperation ops[] = {
NVG_SOURCE_OVER,
NVG_SOURCE_IN,
NVG_SOURCE_OUT,
NVG_ATOP,
NVG_DESTINATION_OVER,
NVG_DESTINATION_IN,
NVG_DESTINATION_OUT,
NVG_DESTINATION_ATOP,
NVG_LIGHTER,
NVG_COPY,
NVG_XOR
};
for (i = 0; i < 11; i++)
{
nvgSave(vg);
nvgTranslate(vg, x + i * 40, y);
nvgGlobalCompositeOperation(vg, NVG_COPY);
imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_a, 1.0);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, 30, 30);
nvgFillPaint(vg, imgPaint);
nvgFill(vg);
nvgGlobalCompositeOperation(vg, ops[i]);
imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_b, 1.0);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, 30, 30);
nvgFillPaint(vg, imgPaint);
nvgFill(vg);
//fill background transparent color to white.
nvgGlobalCompositeOperation(vg, NVG_DESTINATION_OVER);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, 30, 30);
nvgFillColor(vg, nvgRGBA(255,255,255,255));
nvgFill(vg);
nvgRestore(vg);
}
} }


void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, void renderDemo(NVGcontext* vg, float mx, float my, float width, float height,


+ 1
- 1
src/nanovg_gl.h View File

@@ -1138,7 +1138,7 @@ static GLNVGblend glnvg__blendCompositeOperation(NVGcompositeOperationState op)
blend.dstRGB = GL_ONE_MINUS_SRC_ALPHA; blend.dstRGB = GL_ONE_MINUS_SRC_ALPHA;
blend.srcAlpha = GL_ONE; blend.srcAlpha = GL_ONE;
blend.dstAlpha = GL_ONE_MINUS_SRC_ALPHA; blend.dstAlpha = GL_ONE_MINUS_SRC_ALPHA;
}
}
return blend; return blend;
} }




Loading…
Cancel
Save