helloworld.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/bgfx.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. uint32_t width = 1280;
  15. uint32_t height = 720;
  16. uint32_t debug = BGFX_DEBUG_TEXT;
  17. uint32_t reset = BGFX_RESET_VSYNC;
  18. (void)_argc;
  19. (void)_argv;
  20. bgfx_init(BGFX_RENDERER_TYPE_COUNT
  21. , BGFX_PCI_ID_NONE
  22. , 0
  23. , NULL
  24. , NULL
  25. );
  26. bgfx_reset(width, height, reset);
  27. // Enable debug text.
  28. bgfx_set_debug(debug);
  29. bgfx_set_view_clear(0
  30. , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
  31. , 0x303030ff
  32. , 1.0f
  33. , 0
  34. );
  35. while (!entry_process_events(&width, &height, &debug, &reset) )
  36. {
  37. // Set view 0 default viewport.
  38. bgfx_set_view_rect(0, 0, 0, width, height);
  39. // This dummy draw call is here to make sure that view 0 is cleared
  40. // if no other draw calls are submitted to view 0.
  41. bgfx_touch(0);
  42. // Use debug font to print information about this example.
  43. bgfx_dbg_text_clear(0, false);
  44. bgfx_dbg_text_image(uint16_max(width/2/8, 20)-20
  45. , uint16_max(height/2/16, 6)-6
  46. , 40
  47. , 12
  48. , s_logo
  49. , 160
  50. );
  51. bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/25-c99");
  52. bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Initialization and debug text with C99 API.");
  53. // Advance to next frame. Rendering thread will be kicked to
  54. // process submitted rendering primitives.
  55. bgfx_frame();
  56. }
  57. // Shutdown bgfx.
  58. bgfx_shutdown();
  59. return 0;
  60. }