maug
Quick and dirty C mini-augmentation library.
|
An extremely simple single-file annotated example program written with the RetroFlat API.
An extremely simple single-file annotated example program written with the RetroFlat API.
/ * RETROFLT_C must be defined before including retroflt.h ONLY * in one project file! It must be defined once, and only once, * project-wide! The C file where it is defined is where all the * RetroFlat functions will be placed. * / #define RETROFLT_C #include <retroflt.h> / * An example struct containing data fields to be retained between * loop iterations below. * / struct EXAMPLE_DATA { int example; }; / * This is the loop iteration which will be repeatedly called * by retroflat_loop() below, until retroflat_quit() is called. * / void example_loop( struct EXAMPLE_DATA* data ) { struct RETROFLAT_INPUT input_evt; RETROFLAT_IN_KEY input = 0; / * Start loop. * / input = retroflat_poll_input( &input_evt ); switch( input ) { case RETROFLAT_MOUSE_B_LEFT: / * Left mouse button was clicked, do something! * / break; case RETROFLAT_KEY_Q: / * Q key was pressed, so quit! * / retroflat_quit( 0 ); break; } / * === Drawing === * / / * Lock the screen (NULL) for drawing. * / retroflat_draw_lock( NULL ); / * Clear the screen by drawing a big gray rectangle to NULL. * / retroflat_rect( NULL, RETROFLAT_COLOR_GRAY, 0, 0, retroflat_screen_w(), retroflat_screen_h(), RETROFLAT_FLAGS_FILL ); / * Release the screen (NULL) from drawing. * / retroflat_draw_release( NULL ); } int main( int argc, char* argv[] ) { int retval = 0; struct EXAMPLE_DATA data; struct RETROFLAT_ARGS args; / * Startup logging before all else so we catch everything. * / logging_init(); / * Setup the args to retroflat_init() below to create a window * titled "Example Program", and load bitmaps from the "assets" * subdirectory next to the executable. * / args.title = "Example Program"; args.assets_path = "assets"; / * Zero out the data holder. * / memset( &data, '\0', sizeof( struct EXAMPLE_DATA ) ); / * === Setup === * / / * Call the init with the args struct created above. * / retval = retroflat_init( argc, argv, &args ); / * Make sure setup completed successfully! * / if( RETROFLAT_OK != retval ) { goto cleanup; } / * === Main Loop === * / / * Call example_loop( data ) repeatedly, until it calls * retroflat_quit(). Passing it as the first arg means it will * be capped by the framerate. * / retroflat_loop( (retroflat_loop_iter)example_loop, NULL, &data ); cleanup: / * Don't run cleanup stuff under WASM. * / #ifndef RETROFLAT_OS_WASM / * This must be called at the end of the program! * / retroflat_shutdown( retval ); / * Shutdown logging after all else so we catch everything. * / logging_shutdown(); #endif / * RETROFLAT_OS_WASM * / return retval; } / * This should ALWAYS be included after main(), no matter what * platform your program is intended for. * / END_OF_MAIN()