helloworld.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <bx/uint32_t.h>
  6. #include "common.h"
  7. #include "bgfx_utils.h"
  8. #include "logo.h"
  9. class ExampleHelloWorld : public entry::AppI
  10. {
  11. void init(int _argc, char** _argv) BX_OVERRIDE
  12. {
  13. Args args(_argc, _argv);
  14. m_width = 1280;
  15. m_height = 720;
  16. m_debug = BGFX_DEBUG_TEXT;
  17. m_reset = BGFX_RESET_VSYNC;
  18. bgfx::init(args.m_type, args.m_pciId);
  19. bgfx::reset(m_width, m_height, m_reset);
  20. // Enable debug text.
  21. bgfx::setDebug(m_debug);
  22. // Set view 0 clear state.
  23. bgfx::setViewClear(0
  24. , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
  25. , 0x303030ff
  26. , 1.0f
  27. , 0
  28. );
  29. }
  30. virtual int shutdown() BX_OVERRIDE
  31. {
  32. // Shutdown bgfx.
  33. bgfx::shutdown();
  34. return 0;
  35. }
  36. bool update() BX_OVERRIDE
  37. {
  38. if (!entry::processEvents(m_width, m_height, m_debug, m_reset) )
  39. {
  40. // Set view 0 default viewport.
  41. bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  42. // This dummy draw call is here to make sure that view 0 is cleared
  43. // if no other draw calls are submitted to view 0.
  44. bgfx::touch(0);
  45. // Use debug font to print information about this example.
  46. bgfx::dbgTextClear();
  47. bgfx::dbgTextImage(bx::uint16_max(uint16_t(m_width /2/8 ), 20)-20
  48. , bx::uint16_max(uint16_t(m_height/2/16), 6)-6
  49. , 40
  50. , 12
  51. , s_logo
  52. , 160
  53. );
  54. bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/00-helloworld");
  55. bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text.");
  56. bgfx::dbgTextPrintf(0, 4, 0x0f, "Color can be changed with ANSI \e[9;me\e[10;ms\e[11;mc\e[12;ma\e[13;mp\e[14;me\e[0m code too.");
  57. const bgfx::Stats* stats = bgfx::getStats();
  58. bgfx::dbgTextPrintf(0, 6, 0x0f, "Backbuffer %dW x %dH in pixels, debug text %dW x %dH in characters."
  59. , stats->width
  60. , stats->height
  61. , stats->textWidth
  62. , stats->textHeight
  63. );
  64. // Advance to next frame. Rendering thread will be kicked to
  65. // process submitted rendering primitives.
  66. bgfx::frame();
  67. return true;
  68. }
  69. return false;
  70. }
  71. uint32_t m_width;
  72. uint32_t m_height;
  73. uint32_t m_debug;
  74. uint32_t m_reset;
  75. };
  76. ENTRY_IMPLEMENT_MAIN(ExampleHelloWorld);