Files
my_glut/sources/glut.c
2026-03-13 16:48:03 +01:00

87 lines
1.9 KiB
C

#include <stdio.h> /*printf for the main*/
#include <stdlib.h>
#include "../headers/glut.h"
#include "../headers/glut_timers.h"
#include "../headers/glut_graphics.h"
#include "../headers/glut_input.h"
#include "../headers/glut_backend.h"
int terminated=0;
/* sta porcata per cappare la lettura dell'input a 60FPS */
void input_timer( int delayms){
process_inputs();
glutTimerFunc( 17, input_timer, 0);
}
int glutCreateWindow( const char *title){
return create_window_implementation(title);
}
/*all the init functions collassed here*/
void glutInit( char **devPaths, int count){
init_implementation( devPaths, count);
}
void glutInitWindowPosition( int x, int y){}
void glutInitWindowSize( int width, int height ){
init_window_size_implementation( width, height);
}
void glutDisplayFunc( void ( *callback) ( void)){
assignRedrawCallback( callback);
}
void glutKeyboardFunc( void ( *callback) ( unsigned char key, int x, int y)){
assignKeyboardCallback( callback);
}
void glutMainLoop(){
int cappedTimer = 0;
glutPostRedisplay();
/*
SHIEET
*/
glutTimerFunc( 17,input_timer, 0);
while( ! ( terminated || timers_isEmpty())){
cappedTimer = ( cappedTimer + 1) % 17;
if( ! cappedTimer){
/*
process_inputs();
*/
}
decrease_timers();
consume_redraws(); /* the drawing potentially goes at 1000FPS, capped internally at 60 */
sleep_implementation();
}
}
void glutPassiveMotionFunc( void ( *callback) (int x, int y) ){
assignMouseMotionCallback(callback);
}
void glutPostRedisplay(){
issueRedraw();
}
void glutSwapBuffers(){
swap_buffers_implementation();
}
void glutTimerFunc(int ms, void ( *callback)(int), int value){
timer_list_entry* toAdd = malloc( sizeof( timer_list_entry));
toAdd->next = NULL;
toAdd->remaining_ms = ms;
toAdd->callback = callback;
timers_add( toAdd);
}
void glutWarpPointer(int x, int y){
/* this one in glut_input */
warp_pointer_implementation(x, y);
}