Dear GRX
I read with interest the problems of Gernot Kleiter in mail #406
concering animation. As I newcomer to GRX I submit a very short
double-buffering example: a rotating circle. Note by commenting out all
the context & bitblt statements we arrive at a single buffered animation
with flicker. I hope that this is useful. I am interested in the
comments of fellow GRXites to improve this simple program. I run it
under MinGW as I cannot get DJGPP to function on a W2000 laptop.
/* This program animates a filled circle with double buffering */
/* The circle is red on a black background. The circle is of
/* radius r and centre (x,y) which moves in a circular track of radius R
*/
/* centered in the middle of the screen */
#include <stdio.h>
#include <math.h>
#include <grx20.h>
int main()
{
int x, y; /* centre coordinates */
int xMax,yMax; /* extent of the screen */
int Radius=100,r = 10;
double Theta, dTheta,pi; /* Angle of rotation, increment and PI */
GrContext *memory,*screen; /* memory and screen contexts */
GrColor Red,Black; /* circle & background colours */
pi = 3.14159;
dTheta = 0.5*pi/180.0; /* one half a degree increment */
Theta = 0.0; /* starting postion */
GrSetMode(GR_default_graphics );
xMax = GrMaxX(); yMax = GrMaxY();
Red = GrAllocColor(255,0,0);
Black = GrBlack();
memory = GrCreateContext(xMax,yMax,NULL,NULL);
screen = GrScreenContext();
while(1) /* run for ever! */
{
x = xMax/2 + Radius*cos(Theta); /* circle centre */
y = yMax/2 + Radius*sin(Theta);
Theta += dTheta; /* increment angle */
GrSetContext(memory); /* Set memory context */
GrClearContext(Black); /* Set context black */
GrFilledCircle(x,y,r,Red); /* draw red circle */
GrBitBlt(screen,0,0,memory,0,0,xMax-1,yMax-1,GrWRITE); /* copy to
screen */
GrSetContext(screen); /* make visible */
}
return 0;
}
--
Pete Williams
peter.williams173(a)ntlworld.com