entry_linux.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <bx/bx.h>
  6. #if BX_PLATFORM_LINUX
  7. #include "bgfxplatform.h"
  8. #include <stdlib.h>
  9. #include <bx/thread.h>
  10. #include <bx/os.h>
  11. #undef None
  12. #include "entry.h"
  13. #define DEFAULT_WIDTH 1280
  14. #define DEFAULT_HEIGHT 720
  15. extern int _main_(int _argc, char** _argv);
  16. namespace entry
  17. {
  18. struct MainThreadEntry
  19. {
  20. int m_argc;
  21. char** m_argv;
  22. static int32_t threadFunc(void* _userData)
  23. {
  24. MainThreadEntry* self = (MainThreadEntry*)_userData;
  25. return _main_(self->m_argc, self->m_argv);
  26. }
  27. };
  28. struct Context
  29. {
  30. int32_t run(int _argc, char** _argv)
  31. {
  32. m_display = XOpenDisplay(0);
  33. XLockDisplay(m_display);
  34. int32_t screen = DefaultScreen(m_display);
  35. int32_t depth = DefaultDepth(m_display, screen);
  36. Visual* visual = DefaultVisual(m_display, screen);
  37. Window root = RootWindow(m_display, screen);
  38. XSetWindowAttributes windowAttrs;
  39. windowAttrs.colormap =
  40. XCreateColormap(m_display
  41. , root
  42. , visual
  43. , AllocNone
  44. );
  45. windowAttrs.background_pixmap = 0;
  46. windowAttrs.border_pixel = 0;
  47. m_window = XCreateWindow(m_display
  48. , root
  49. , 0, 0
  50. , DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, depth
  51. , InputOutput
  52. , visual
  53. , CWBorderPixel|CWColormap
  54. , &windowAttrs
  55. );
  56. XMapRaised(m_display, m_window);
  57. XFlush(m_display);
  58. XUnlockDisplay(m_display);
  59. // XResizeWindow(s_display, s_window, _width, _height);
  60. bgfx::x11SetDisplayWindow(m_display, m_window);
  61. MainThreadEntry mte;
  62. mte.m_argc = _argc;
  63. mte.m_argv = _argv;
  64. bx::Thread thread;
  65. thread.init(mte.threadFunc, &mte);
  66. thread.shutdown();
  67. return EXIT_SUCCESS;
  68. }
  69. Display* m_display;
  70. Window m_window;
  71. };
  72. static Context s_ctx;
  73. Event::Enum poll()
  74. {
  75. return Event::Nop;
  76. }
  77. } // namespace entry
  78. int main(int _argc, char** _argv)
  79. {
  80. using namespace entry;
  81. return s_ctx.run(_argc, _argv);
  82. }
  83. #endif // BX_PLATFORM_LINUX