X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=progs%2Fsamples%2Fstar.c;h=2c44ebfd49e95fec5a56a7030a23eb38a8b7cf72;hb=aa0b671422880b99dc178d43d1e4e1a3f766bf7f;hp=180585e121896b0dd766649ead4d48eb80156791;hpb=afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1c;p=mesa.git diff --git a/progs/samples/star.c b/progs/samples/star.c index 180585e1218..2c44ebfd49e 100644 --- a/progs/samples/star.c +++ b/progs/samples/star.c @@ -45,7 +45,7 @@ enum { #define MAXSTARS 400 #define MAXPOS 10000 -#define MAXWARP 10 +#define MAXWARP 500 #define MAXANGLES 6000 @@ -67,19 +67,19 @@ starRec stars[MAXSTARS]; float sinTable[MAXANGLES]; -float Sin(float angle) +static float Sin(float angle) { return (sinTable[(GLint)angle]); } -float Cos(float angle) +static float Cos(float angle) { return (sinTable[((GLint)angle+(MAXANGLES/4))%MAXANGLES]); } -void NewStar(GLint n, GLint d) +static void NewStar(GLint n, GLint d) { if (rand()%4 == 0) { @@ -101,7 +101,7 @@ void NewStar(GLint n, GLint d) } } -void RotatePoint(float *x, float *y, float rotation) +static void RotatePoint(float *x, float *y, float rotation) { float tmpX, tmpY; @@ -111,10 +111,17 @@ void RotatePoint(float *x, float *y, float rotation) *y = tmpY; } -void MoveStars(void) +static void MoveStars(void) { float offset; GLint n; + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = 85.*(t - t0); + t0 = t; offset = speed * 60.0; @@ -122,17 +129,20 @@ void MoveStars(void) stars[n].x[1] = stars[n].x[0]; stars[n].y[1] = stars[n].y[0]; stars[n].z[1] = stars[n].z[0]; - stars[n].x[0] += stars[n].offsetX; - stars[n].y[0] += stars[n].offsetY; - stars[n].z[0] -= offset; - stars[n].rotation += stars[n].offsetR; + stars[n].x[0] += stars[n].offsetX*dt; + stars[n].y[0] += stars[n].offsetY*dt; + stars[n].z[0] -= offset*dt; + stars[n].rotation += stars[n].offsetR*dt; if (stars[n].rotation > MAXANGLES) { stars[n].rotation = 0.0; } + else if (stars[n].rotation < 0.0) { + stars[n].rotation += 360.0; + } } } -GLenum StarPoint(GLint n) +static GLenum StarPoint(GLint n) { float x0, y0, x1, y1, width; GLint i; @@ -180,7 +190,7 @@ GLenum StarPoint(GLint n) } } -void ShowStars(void) +static void ShowStars(void) { GLint n; @@ -219,7 +229,7 @@ static void Init(void) glDisable(GL_DITHER); } -void Reshape(int width, int height) +static void Reshape(int width, int height) { windW = (GLint)width; @@ -250,7 +260,7 @@ static void Key(unsigned char key, int x, int y) } } -void Draw(void) +static void Draw(void) { MoveStars(); @@ -281,7 +291,7 @@ static GLenum Args(int argc, char **argv) { GLint i; - doubleBuffer = GL_FALSE; + doubleBuffer = GL_TRUE; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-sb") == 0) { @@ -293,7 +303,11 @@ static GLenum Args(int argc, char **argv) return GL_TRUE; } -void GLUTCALLBACK glut_post_redisplay_p(void) +#if !defined(GLUTCALLBACK) +#define GLUTCALLBACK +#endif + +static void GLUTCALLBACK glut_post_redisplay_p(void) { glutPostRedisplay(); }