helloworld.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <bgfx.c99.h>
  6. #include "../00-helloworld/logo.h"
  7. extern bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset);
  8. uint16_t uint16_max(uint16_t _a, uint16_t _b)
  9. {
  10. return _a < _b ? _b : _a;
  11. }
  12. int _main_(int _argc, char** _argv)
  13. {
  14. (void)_argc;
  15. (void)_argv;
  16. uint32_t width = 1280;
  17. uint32_t height = 720;
  18. uint32_t debug = BGFX_DEBUG_TEXT;
  19. uint32_t reset = BGFX_RESET_VSYNC;
  20. bgfx_init(BGFX_RENDERER_TYPE_COUNT, NULL, NULL);
  21. bgfx_reset(width, height, reset);
  22. // Enable debug text.
  23. bgfx_set_debug(debug);
  24. bgfx_set_view_clear(0
  25. , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
  26. , 0x303030ff
  27. , 1.0f
  28. , 0
  29. );
  30. while (!entry_process_events(&width, &height, &debug, &reset) )
  31. {
  32. // Set view 0 default viewport.
  33. bgfx_set_view_rect(0, 0, 0, width, height);
  34. // This dummy draw call is here to make sure that view 0 is cleared
  35. // if no other draw calls are submitted to view 0.
  36. bgfx_submit(0, 0);
  37. // Use debug font to print information about this example.
  38. bgfx_dbg_text_clear(0, false);
  39. bgfx_dbg_text_image(uint16_max(width/2/8, 20)-20
  40. , uint16_max(height/2/16, 6)-6
  41. , 40
  42. , 12
  43. , s_logo
  44. , 160
  45. );
  46. bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/25-c99");
  47. bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Initialization and debug text with C99 API.");
  48. // Advance to next frame. Rendering thread will be kicked to
  49. // process submitted rendering primitives.
  50. bgfx_frame();
  51. }
  52. // Shutdown bgfx.
  53. bgfx_shutdown();
  54. return 0;
  55. }