2
0

main.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*================================================================
  2. * Copyright: 2020 John Jackson
  3. * HellGS
  4. A Bare bones c++ application for getting started using `gunslinger`.
  5. Creates an appplication context, an engine context, and then
  6. opens a main window for you using the rendering context.
  7. Press `esc` to exit the application.
  8. =================================================================*/
  9. #include <gs.h>
  10. // Forward Decls.
  11. gs_result app_update(); // Use to update your application
  12. int main(int argc, char** argv)
  13. {
  14. // This is our app description. It gives internal hints to our engine for various things like
  15. // window size, title, as well as update, init, and shutdown functions to be run.
  16. gs_application_desc_t app = {0};
  17. app.window_title = "Hello, CPP";
  18. app.window_width = 800;
  19. app.window_height = 600;
  20. app.update = &app_update;
  21. // Construct internal instance of our engine
  22. gs_engine_t* engine = gs_engine_construct(app);
  23. // Run the internal engine loop until completion
  24. gs_result res = engine->run();
  25. // Check result of engine after exiting loop
  26. if (res != gs_result_success)
  27. {
  28. gs_println("Error: Engine did not successfully finish running.");
  29. return -1;
  30. }
  31. gs_println("Gunslinger exited successfully.");
  32. return 0;
  33. }
  34. // Update your application here
  35. gs_result app_update()
  36. {
  37. // Grab global instance of engine
  38. gs_engine_t* engine = gs_engine_instance();
  39. // If we press the escape key, exit the application
  40. if (engine->ctx.platform->key_pressed(gs_keycode_esc))
  41. {
  42. return gs_result_success;
  43. }
  44. // Otherwise, continue
  45. return gs_result_in_progress;
  46. }