54 lines
954 B
C
54 lines
954 B
C
#include <stddef.h> /* NULL */
|
|
|
|
#include "../headers/glut_graphics.h"
|
|
|
|
/* each request simply sets a flag to be consumed by the main loop, (no need for more than one redraw per cycle) */
|
|
int must_redraw = 0;
|
|
const int REDRAW_TIMER_INIT = 16;
|
|
int redraw_timer = 0;
|
|
|
|
void (*redraw_callback) (void) = NULL;
|
|
|
|
void assignRedrawCallback( void ( *callback) ( void)){
|
|
if( NULL != redraw_callback){
|
|
return;
|
|
}
|
|
|
|
redraw_callback = callback;
|
|
}
|
|
|
|
void issueRedraw(){
|
|
must_redraw = 1;
|
|
}
|
|
|
|
void consume_redraws(){
|
|
/* ensuring a minimum interval of 1/FPS secs between redraws
|
|
if the timer
|
|
*/
|
|
redraw_timer--;
|
|
if( redraw_timer < 0){
|
|
redraw_timer = 0;
|
|
}
|
|
else{
|
|
return;
|
|
}
|
|
|
|
if( 0 == must_redraw){
|
|
return;
|
|
}
|
|
|
|
must_redraw = 0;
|
|
|
|
/* what to do if the redraw callback is not set?
|
|
is not necessarily an error
|
|
*/
|
|
if( NULL == redraw_callback){
|
|
return;
|
|
}
|
|
|
|
redraw_timer = REDRAW_TIMER_INIT;
|
|
/* here the drawing implementation */
|
|
|
|
redraw_callback();
|
|
}
|