diff --git a/src/animation.c b/src/animation.c index 1fdc413..d54bb79 100644 --- a/src/animation.c +++ b/src/animation.c @@ -104,11 +104,15 @@ int imageLoad(const char *path, int *outWidth, int *outHeight, unsigned char **o } -unsigned int imageToGLTexture(int width, int height, const unsigned char *pixels, int smooth, int horWrap, int vertWrap) { +unsigned int imageToGLTexture(int width, int height, const void *pixels, int wrap) + { return imageToGLTextureEx(width, height, pixels, wrap, wrap, TRUE, TRUE); } + + +unsigned int imageToGLTextureEx(int width, int height, const void *pixels, int horWrap, int vertWrap, int smooth, int mipMap) { // convert to float and premult alpha size_t count = (size_t)width*height*4; float *buffer = (float*)malloc(count*sizeof(float)); - const unsigned char *pp = pixels; + const unsigned char *pp = (const unsigned char *)pixels; for(float *p = buffer, *end = p + count; p < end; p += 4, pp += 4) { if (pp[3]) { float a = pp[3]/255.f; @@ -177,7 +181,7 @@ unsigned int imageToGLTexture(int width, int height, const unsigned char *pixels glGenTextures(1, &texid); glBindTexture(GL_TEXTURE_2D, texid); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, smooth ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, smooth ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, smooth ? (mipMap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR): (mipMap ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, horWrap ? GL_REPEAT : GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, vertWrap ? GL_REPEAT : GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -0.7f); @@ -204,6 +208,7 @@ unsigned int imageToGLTexture(int width, int height, const unsigned char *pixels glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuffer); ++level; + if (!mipMap) break; if (w <= 1 && h <= 1) break; if (w > 1) mipx(buffer, &w, &h); if (h > 1) mipy(buffer, &w, &h); @@ -233,7 +238,7 @@ static HeliTexture* loadTexture(const char *key) { int w = 0, h = 0; unsigned char *pixels = NULL; if (imageLoad(key+3, &w, &h, &pixels)) { - texture->id = imageToGLTexture(w, h, pixels, key[0] == 'L', key[1] == 'W', key[2] == 'W'); + texture->id = imageToGLTextureEx(w, h, pixels, key[1] == 'W', key[2] == 'W', key[0] == 'L', TRUE); free(pixels); } } diff --git a/src/animation.h b/src/animation.h index c9a6aed..7280fec 100644 --- a/src/animation.h +++ b/src/animation.h @@ -8,12 +8,17 @@ typedef struct _Animation *Animation; int imageLoad(const char *path, int *outWidth, int *outHeight, unsigned char **outPixels); -unsigned int imageToGLTexture(int width, int height, const unsigned char *pixels, int smooth, int horWrap, int vertWrap); +//int imageSave(const char *path, int width, int *height, const void *pixels); +unsigned int imageToGLTexture(int width, int height, const void *pixels, int wrap); +unsigned int imageToGLTextureEx(int width, int height, const void *pixels, int horWrap, int vertWrap, int smooth, int mipMap); +//int imageFromGLTexture(unsigned int texid, int *outWidth, int *outHeight, unsigned char **outPixels); Animation createAnimation(const char *path); Animation createAnimationEx(const char *path, int smooth, int horWrap, int vertWrap); Animation createAnimationFromGLTexId(unsigned int texid); +Animation createAnimationFromImage(int width, int height, const void *pixels, int wrap); +Animation createAnimationFromImageEx(int width, int height, const void *pixels, int horWrap, int vertWrap, int smooth, int mipMap); Animation createAnimationEmpty(); void animationDestroy(Animation animation); @@ -21,6 +26,7 @@ Animation animationClone(Animation animation); Animation animationCloneEx(Animation animation, int start, int count); unsigned int animationGetGLTexId(Animation animation); +//void animationGLTexIdSetOwnership(unsigned int texid, int own); int animationGetFramesCount(Animation animation); void animationInsert(Animation animation, int index, Animation other); diff --git a/src/drawing.c b/src/drawing.c index fbbf7d9..fe27909 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -122,6 +122,9 @@ void scale(double x, double y) { glScaled(x, y, 1); } void zoom(double z) { scale(z, z); } +void noTransform() + { glLoadIdentity(); } + void cliprect(double x, double y, double width, double height) { double eq[4][4] = { diff --git a/src/drawing.h b/src/drawing.h index df5e59a..5768946 100644 --- a/src/drawing.h +++ b/src/drawing.h @@ -53,6 +53,8 @@ void translate(double x, double y); void rotate(double angle); void zoom(double z); void scale(double x, double y); +void noTransform(); + void cliprect(double x, double y, double width, double height); void noClip();