helloworld.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2011-2016 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. int32_t _main_(int32_t _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, (uint16_t)width, (uint16_t)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(
  45. uint16_max( (uint16_t)width /2/8, 20)-20
  46. , uint16_max( (uint16_t)height/2/16, 6)-6
  47. , 40
  48. , 12
  49. , s_logo
  50. , 160
  51. );
  52. bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/25-c99");
  53. bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Initialization and debug text with C99 API.");
  54. // Advance to next frame. Rendering thread will be kicked to
  55. // process submitted rendering primitives.
  56. bgfx_frame(false);
  57. }
  58. // Shutdown bgfx.
  59. bgfx_shutdown();
  60. return 0;
  61. }