diff --git a/tests/cursor.c b/tests/cursor.c index 6545eced..4e673871 100644 --- a/tests/cursor.c +++ b/tests/cursor.c @@ -86,7 +86,7 @@ static void command_callback(int key) int w = cursorSize[currentSize].w; int h = cursorSize[currentSize].h; int x, y, i = 0; - unsigned char image[4 * w * h]; + unsigned char *image = malloc(4 * w * h); for (y = 0; y < h; y++) { @@ -100,8 +100,8 @@ static void command_callback(int key) } cursor = glfwCreateCursor(w, h, w / 2, h / 2, 0, image); - currentSize = (currentSize + 1) % SizeCount; + free(image); } } break; diff --git a/tests/cursoranim.c b/tests/cursoranim.c index a74cf509..b7c78600 100644 --- a/tests/cursoranim.c +++ b/tests/cursoranim.c @@ -32,25 +32,33 @@ #include #include -#define SIZE 64 +#ifdef min + #undef min +#endif +#ifdef max + #undef max +#endif + +#define SIZE 64 // cursor size (width & height) +#define N 60 // number of frames unsigned char buffer[4 * SIZE * SIZE]; -static inline float max(float a, float b) { return a > b ? a : b; } -static inline float min(float a, float b) { return a < b ? a : b; } +static float max(float a, float b) { return a > b ? a : b; } +static float min(float a, float b) { return a < b ? a : b; } static float star(int x, int y, float t) { float c = SIZE / 2.0f; - float i = (0.25f * sin(2.0f * 3.1415926f * t) + 0.75f); + float i = (0.25f * (float)sin(2.0f * 3.1415926f * t) + 0.75f); float k = SIZE * 0.046875f * i; - float dist = sqrt((x - c) * (x - c) + (y - c) * (y - c)); + float dist = (float)sqrt((x - c) * (x - c) + (y - c) * (y - c)); float salpha = 1.0f - dist / c; - float xalpha = (float)x == c ? c : k / fabs(x - c); - float yalpha = (float)y == c ? c : k / fabs(y - c); + float xalpha = (float)x == c ? c : k / (float)fabs(x - c); + float yalpha = (float)y == c ? c : k / (float)fabs(y - c); return max(0.0f, min(1.0f, i * salpha * 0.2f + salpha * xalpha * yalpha)); } @@ -66,7 +74,7 @@ static GLFWcursor* load_frame(float t) buffer[i++] = 255; buffer[i++] = 255; buffer[i++] = 255; - buffer[i++] = 255 * star(x, y, t); + buffer[i++] = (unsigned char)(255 * star(x, y, t)); } } @@ -75,7 +83,6 @@ static GLFWcursor* load_frame(float t) int main(void) { - const int N = 60; int i; double t0, t1, frameTime = 0.0;