diff --git a/src/animation.c b/src/animation.c index 1ca5b76..01782d5 100644 --- a/src/animation.c +++ b/src/animation.c @@ -310,12 +310,12 @@ unsigned int pixelGet(const void *pixel) { | (((unsigned int)p[3]) << 0); } -void pixelSet(void *pixel, unsigned int color) { +void pixelSet(void *pixel, unsigned int colorCode) { unsigned char *p = (unsigned char *)pixel; - p[0] = (color >> 24); - p[1] = (color >> 16) & 0xFF; - p[2] = (color >> 8) & 0xFF; - p[3] = (color ) & 0xFF; + p[0] = (colorCode >> 24); + p[1] = (colorCode >> 16) & 0xFF; + p[2] = (colorCode >> 8) & 0xFF; + p[3] = (colorCode ) & 0xFF; } unsigned int imageGetPixel(int width, int height, const void *pixels, int x, int y) { @@ -323,13 +323,11 @@ unsigned int imageGetPixel(int width, int height, const void *pixels, int x, int return pixelGet((const unsigned char *)pixels + 4*((size_t)width*y + x)); } -void imageSetPixel(int width, int height, void *pixels, int x, int y, unsigned int color) { +void imageSetPixel(int width, int height, void *pixels, int x, int y, unsigned int colorCode) { if (x < 0 || x >= width || y < 0 || y >= height || !pixels) return; - pixelSet((unsigned char *)pixels + 4*((size_t)width*y + x), color); + pixelSet((unsigned char *)pixels + 4*((size_t)width*y + x), colorCode); } -void imageSetPixel(int width, int height, void *pixels, int x, int y, unsigned int color); - static void unloadTexture(HeliTexture *texture) { diff --git a/src/animation.h b/src/animation.h index 3876f18..158b926 100644 --- a/src/animation.h +++ b/src/animation.h @@ -19,9 +19,9 @@ int imageFromViewport(int *outWidth, int *outHeight, unsigned char **outPixels); int viewportSave(const char *path); unsigned int pixelGet(const void *pixel); -void pixelSet(void *pixel, unsigned int color); +void pixelSet(void *pixel, unsigned int colorCode); unsigned int imageGetPixel(int width, int height, const void *pixels, int x, int y); -void imageSetPixel(int width, int height, void *pixels, int x, int y, unsigned int color); +void imageSetPixel(int width, int height, void *pixels, int x, int y, unsigned int colorCode); Animation createAnimation(const char *path); diff --git a/src/common.c b/src/common.c index 171085a..dcef0dd 100644 --- a/src/common.c +++ b/src/common.c @@ -193,10 +193,10 @@ unsigned int colorByHSV(double h, double s, double v) unsigned int colorByYUV(double y, double u, double v) { return colorByYUVA(y, u, v, 1); } -double colorGetRed (unsigned int color) { return ( color >> 24 )/255.0; } -double colorGetGreen(unsigned int color) { return ((color >> 16) & 0xFFu)/255.0; } -double colorGetBlue (unsigned int color) { return ((color >> 8) & 0xFFu)/255.0; } -double colorGetAlpha(unsigned int color) { return ( color & 0xFFu)/255.0; } +double colorGetRed (unsigned int colorCode) { return ( colorCode >> 24 )/255.0; } +double colorGetGreen(unsigned int colorCode) { return ((colorCode >> 16) & 0xFFu)/255.0; } +double colorGetBlue (unsigned int colorCode) { return ((colorCode >> 8) & 0xFFu)/255.0; } +double colorGetAlpha(unsigned int colorCode) { return ( colorCode & 0xFFu)/255.0; } void heliColorToDouble(unsigned int code, double *rgba) { rgba[0] = colorGetRed (code); rgba[1] = colorGetGreen(code); @@ -204,20 +204,20 @@ void heliColorToDouble(unsigned int code, double *rgba) { rgba[3] = colorGetAlpha(code); } -double colorGetYLuminance(unsigned int color) { - return rgbToYuv[0][0]*colorGetRed (color) - + rgbToYuv[0][1]*colorGetGreen(color) - + rgbToYuv[0][2]*colorGetBlue (color); +double colorGetYLuminance(unsigned int colorCode) { + return rgbToYuv[0][0]*colorGetRed (colorCode) + + rgbToYuv[0][1]*colorGetGreen(colorCode) + + rgbToYuv[0][2]*colorGetBlue (colorCode); } -double colorGetUChrominance(unsigned int color) { - return rgbToYuv[1][0]*colorGetRed (color) - + rgbToYuv[1][1]*colorGetGreen(color) - + rgbToYuv[1][2]*colorGetBlue (color); +double colorGetUChrominance(unsigned int colorCode) { + return rgbToYuv[1][0]*colorGetRed (colorCode) + + rgbToYuv[1][1]*colorGetGreen(colorCode) + + rgbToYuv[1][2]*colorGetBlue (colorCode); } -double colorGetVChrominance(unsigned int color) { - return rgbToYuv[1][0]*colorGetRed (color) - + rgbToYuv[1][1]*colorGetGreen(color) - + rgbToYuv[1][2]*colorGetBlue (color); +double colorGetVChrominance(unsigned int colorCode) { + return rgbToYuv[1][0]*colorGetRed (colorCode) + + rgbToYuv[1][1]*colorGetGreen(colorCode) + + rgbToYuv[1][2]*colorGetBlue (colorCode); } @@ -225,10 +225,10 @@ static int colorMin(double *c) { return c[0] < c[1] ? (c[0] < c[2] ? 0 : 2) : (c[1] < c[2] ? 1 : 2); } static int colorMax(double *c) { return c[0] > c[1] ? (c[0] > c[2] ? 0 : 2) : (c[1] > c[2] ? 1 : 2); } -double colorGetHue(unsigned int color) { - double rgb[] = { colorGetRed (color), - colorGetGreen(color), - colorGetBlue (color) }; +double colorGetHue(unsigned int colorCode) { + double rgb[] = { colorGetRed (colorCode), + colorGetGreen(colorCode), + colorGetBlue (colorCode) }; int cmin = colorMin(rgb); int cmax = colorMax(rgb); double d = rgb[cmax] - rgb[cmin]; @@ -244,18 +244,18 @@ double colorGetHue(unsigned int color) { } return h; } -double colorGetSaturation(unsigned int color) { - double rgb[] = { colorGetRed (color), - colorGetGreen(color), - colorGetBlue (color) }; +double colorGetSaturation(unsigned int colorCode) { + double rgb[] = { colorGetRed (colorCode), + colorGetGreen(colorCode), + colorGetBlue (colorCode) }; int cmin = colorMin(rgb); int cmax = colorMax(rgb); return rgb[cmax] > HELI_PRECISION ? (rgb[cmax] - rgb[cmin])/rgb[cmax] : 0; } -double colorGetValue(unsigned int color) { - double rgb[] = { colorGetRed (color), - colorGetGreen(color), - colorGetBlue (color) }; +double colorGetValue(unsigned int colorCode) { + double rgb[] = { colorGetRed (colorCode), + colorGetGreen(colorCode), + colorGetBlue (colorCode) }; return rgb[colorMax(rgb)]; } diff --git a/src/drawing.c b/src/drawing.c index 3e1d383..c3198c0 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -4,7 +4,6 @@ #include "drawing.h" -static double colorBack[4] = {1, 1, 1, 1}; static double *path; static size_t pathSize; static size_t pathAllocated; @@ -68,8 +67,14 @@ void heliDrawingResetTexture() { } -void background(unsigned int colorCode) - { heliColorToDouble(colorCode, colorBack); } +void background(unsigned int colorCode) { + double color[4]; + heliColorToDouble(colorCode, color); + glClearColor(color[0], color[1], color[2], color[3]); +} +void clear() + { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } + void fill(unsigned int colorCode) { heliColorToDouble(colorCode, heliDrawingGetState()->fillColor); } void fillTexture(Animation animation, double x, double y, double width, double height, int fixed) { @@ -783,11 +788,12 @@ void resetStateEx(unsigned int flags) { if (flags & STATE_STROKE_WIDTH ) strokeWidth(1); if (flags & STATE_TEXT_ALIGN ) textAlign(HALIGN_LEFT, VALIGN_TOP); if (flags & STATE_TEXT_SIZE ) textSize(24); - if (flags & STATE_TRANSFORM ) noTransform(); - if (flags & STATE_CLIP ) noClip(); if (flags & STATE_TARGET_FRAMEBUFFER) targetEx(NULL, FALSE, FALSE); if (flags & STATE_TARGET_VIEWPORT ) viewportByWindow(); if (flags & STATE_TARGET_PROJECTION ) projectionByViewport(); + if (flags & STATE_BACKGROUND ) background(colorByRGBA(1, 1, 1, 1)); + if (flags & STATE_TRANSFORM ) noTransform(); + if (flags & STATE_CLIP ) noClip(); } void saveState() @@ -838,8 +844,7 @@ void restoreState() { void heliDrawingClearFrame() { unsigned int prev; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (int*)&prev); - glClearColor(colorBack[0], colorBack[1], colorBack[2], colorBack[3]); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + clear(); if (heliGLBindFramebufferPtr) heliGLBindFramebufferPtr(GL_DRAW_FRAMEBUFFER, prev); } diff --git a/src/drawing.h b/src/drawing.h index 197b2b9..37f8e6d 100644 --- a/src/drawing.h +++ b/src/drawing.h @@ -7,23 +7,24 @@ typedef enum _StateFlags { - STATE_FILL_COLOR = 1 << 0, - STATE_FILL_TEXTURE = 1 << 1, + STATE_FILL_COLOR = 1 << 0, + STATE_FILL_TEXTURE = 1 << 1, - STATE_STROKE_COLOR = 1 << 2, - STATE_STROKE_TEXTURE = 1 << 3, - STATE_STROKE_WIDTH = 1 << 4, + STATE_STROKE_COLOR = 1 << 2, + STATE_STROKE_TEXTURE = 1 << 3, + STATE_STROKE_WIDTH = 1 << 4, - STATE_TEXT_ALIGN = 1 << 5, - STATE_TEXT_SIZE = 1 << 6, - STATE_TEXT_FONT = 1 << 7, - - STATE_TRANSFORM = 1 << 8, - STATE_CLIP = 1 << 9, + STATE_TEXT_ALIGN = 1 << 5, + STATE_TEXT_SIZE = 1 << 6, + STATE_TEXT_FONT = 1 << 7, - STATE_TARGET_FRAMEBUFFER = 1 << 10, - STATE_TARGET_VIEWPORT = 1 << 11, - STATE_TARGET_PROJECTION = 1 << 12, + STATE_TARGET_FRAMEBUFFER = 1 << 8, + STATE_TARGET_VIEWPORT = 1 << 9, + STATE_TARGET_PROJECTION = 1 << 10, + + STATE_BACKGROUND = 1 << 11, + STATE_TRANSFORM = 1 << 12, + STATE_CLIP = 1 << 13, STATE_FILL = STATE_FILL_COLOR | STATE_FILL_TEXTURE, @@ -40,6 +41,8 @@ typedef enum _StateFlags { STATE_ALL = STATE_FILL | STATE_STROKE | STATE_TEXT + | STATE_TARGET + | STATE_BACKGROUND | STATE_TRANSFORM | STATE_CLIP | STATE_TARGET, @@ -47,6 +50,7 @@ typedef enum _StateFlags { void background(unsigned int colorCode); +void clear(); void fill(unsigned int colorCode); void fillTexture(Animation animation, double x, double y, double width, double height, int fixed); @@ -87,18 +91,18 @@ unsigned int colorByHSVA(double h, double s, double v, double a); unsigned int colorByYUV(double y, double u, double v); unsigned int colorByYUVA(double y, double u, double v, double a); -double colorGetRed(unsigned int color); -double colorGetGreen(unsigned int color); -double colorGetBlue(unsigned int color); -double colorGetAlpha(unsigned int color); +double colorGetRed(unsigned int colorCode); +double colorGetGreen(unsigned int colorCode); +double colorGetBlue(unsigned int colorCode); +double colorGetAlpha(unsigned int colorCode); -double colorGetHue(unsigned int color); -double colorGetSaturation(unsigned int color); -double colorGetValue(unsigned int color); +double colorGetHue(unsigned int colorCode); +double colorGetSaturation(unsigned int colorCode); +double colorGetValue(unsigned int colorCode); -double colorGetYLuminance(unsigned int color); -double colorGetUChrominance(unsigned int color); -double colorGetVChrominance(unsigned int color); +double colorGetYLuminance(unsigned int colorCode); +double colorGetUChrominance(unsigned int colorCode); +double colorGetVChrominance(unsigned int colorCode); void rect(double x, double y, double width, double height); diff --git a/src/framebuffer.c b/src/framebuffer.c index f2b02b3..06ead48 100644 --- a/src/framebuffer.c +++ b/src/framebuffer.c @@ -3,6 +3,7 @@ #include "private.h" #include "world.h" #include "framebuffer.h" +#include "drawing.h" typedef struct _HeliFramebufferDesc { diff --git a/src/gl.c b/src/gl.c index 6ff5afe..cdfbbba 100644 --- a/src/gl.c +++ b/src/gl.c @@ -179,6 +179,8 @@ void heliGLGetCommonState(HeliGLCommonState *state, unsigned int flags) { glGetIntegerv(GL_VIEWPORT, state->viewport); if (state->flags & STATE_TARGET_PROJECTION) glGetDoublev(GL_PROJECTION_MATRIX, state->projectionMatrix); + if (state->flags & STATE_BACKGROUND) + glGetDoublev(GL_COLOR_CLEAR_VALUE, state->clearColor); } @@ -222,5 +224,7 @@ void heliGLSetCommonState(const HeliGLCommonState *state) { glLoadMatrixd(state->projectionMatrix); glMatrixMode(mode); } + if (state->flags & STATE_BACKGROUND) + glClearColor(state->clearColor[0], state->clearColor[1], state->clearColor[2], state->clearColor[3]); } diff --git a/src/private.h b/src/private.h index 54f0fc3..3b5821e 100644 --- a/src/private.h +++ b/src/private.h @@ -121,6 +121,7 @@ typedef struct _HeliGLCommonState { unsigned int flags; double modelviewMatrix[16]; double projectionMatrix[16]; + double clearColor[4]; int viewport[4]; unsigned int framebuffer_read_id; unsigned int framebuffer_draw_id;