summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/20-nanovg/nanovg.cpp')
-rw-r--r--3rdparty/bgfx/examples/20-nanovg/nanovg.cpp129
1 files changed, 77 insertions, 52 deletions
diff --git a/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp b/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp
index f667ba180c2..206bca10237 100644
--- a/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp
+++ b/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp
@@ -1201,80 +1201,105 @@ void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float he
nvgRestore(vg);
}
-int _main_(int _argc, char** _argv)
+class ExampleNanoVG : public entry::AppI
{
- Args args(_argc, _argv);
+ void init(int _argc, char** _argv) BX_OVERRIDE
+ {
+ Args args(_argc, _argv);
- uint32_t width = 1280;
- uint32_t height = 720;
- uint32_t debug = BGFX_DEBUG_TEXT;
- uint32_t reset = BGFX_RESET_VSYNC;
+ m_width = 1280;
+ m_height = 720;
+ m_debug = BGFX_DEBUG_TEXT;
+ m_reset = BGFX_RESET_VSYNC;
- bgfx::init(args.m_type, args.m_pciId);
- bgfx::reset(width, height, reset);
+ bgfx::init(args.m_type, args.m_pciId);
+ bgfx::reset(m_width, m_height, m_reset);
- // Enable debug text.
- bgfx::setDebug(debug);
+ // Enable debug text.
+ bgfx::setDebug(m_debug);
- // Set view 0 clear state.
- bgfx::setViewClear(0
- , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
- , 0x303030ff
- , 1.0f
- , 0
- );
+ // Set view 0 clear state.
+ bgfx::setViewClear(0
+ , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
+ , 0x303030ff
+ , 1.0f
+ , 0
+ );
+
+ imguiCreate();
+
+ m_nvg = nvgCreate(1, 0);
+ bgfx::setViewSeq(0, true);
+
+ loadDemoData(m_nvg, &m_data);
+
+ bndSetFont(nvgCreateFont(m_nvg, "droidsans", "font/droidsans.ttf") );
+ bndSetIconImage(nvgCreateImage(m_nvg, "images/blender_icons16.png", 0) );
+
+ m_timeOffset = bx::getHPCounter();
+ }
- imguiCreate();
+ int shutdown() BX_OVERRIDE
+ {
+ freeDemoData(m_nvg, &m_data);
- NVGcontext* nvg = nvgCreate(1, 0);
- bgfx::setViewSeq(0, true);
+ nvgDelete(m_nvg);
- DemoData data;
- loadDemoData(nvg, &data);
+ imguiDestroy();
- bndSetFont(nvgCreateFont(nvg, "droidsans", "font/droidsans.ttf") );
- bndSetIconImage(nvgCreateImage(nvg, "images/blender_icons16.png", 0) );
+ // Shutdown bgfx.
+ bgfx::shutdown();
- int64_t timeOffset = bx::getHPCounter();
+ return 0;
+ }
- entry::MouseState mouseState;
- while (!entry::processEvents(width, height, debug, reset, &mouseState) )
+ bool update() BX_OVERRIDE
{
- int64_t now = bx::getHPCounter();
- const double freq = double(bx::getHPFrequency() );
- float time = (float)( (now-timeOffset)/freq);
+ if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
+ {
+ int64_t now = bx::getHPCounter();
+ const double freq = double(bx::getHPFrequency() );
+ float time = (float)( (now-m_timeOffset)/freq);
- // Set view 0 default viewport.
- bgfx::setViewRect(0, 0, 0, width, height);
+ // Set view 0 default viewport.
+ bgfx::setViewRect(0, 0, 0, m_width, m_height);
- // This dummy draw call is here to make sure that view 0 is cleared
- // if no other draw calls are submitted to view 0.
- bgfx::touch(0);
+ // This dummy draw call is here to make sure that view 0 is cleared
+ // if no other draw calls are submitted to view 0.
+ bgfx::touch(0);
- // Use debug font to print information about this example.
- bgfx::dbgTextClear();
- bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/20-nanovg");
- bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: NanoVG is small antialiased vector graphics rendering library.");
+ // Use debug font to print information about this example.
+ bgfx::dbgTextClear();
+ bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/20-nanovg");
+ bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: NanoVG is small antialiased vector graphics rendering library.");
- nvgBeginFrame(nvg, width, height, 1.0f);
+ nvgBeginFrame(m_nvg, m_width, m_height, 1.0f);
- renderDemo(nvg, float(mouseState.m_mx), float(mouseState.m_my), float(width), float(height), time, 0, &data);
+ renderDemo(m_nvg, float(m_mouseState.m_mx), float(m_mouseState.m_my), float(m_width), float(m_height), time, 0, &m_data);
- nvgEndFrame(nvg);
+ nvgEndFrame(m_nvg);
- // Advance to next frame. Rendering thread will be kicked to
- // process submitted rendering primitives.
- bgfx::frame();
+ // Advance to next frame. Rendering thread will be kicked to
+ // process submitted rendering primitives.
+ bgfx::frame();
+
+ return true;
+ }
+
+ return false;
}
- freeDemoData(nvg, &data);
+ uint32_t m_width;
+ uint32_t m_height;
+ uint32_t m_debug;
+ uint32_t m_reset;
- nvgDelete(nvg);
+ entry::MouseState m_mouseState;
- imguiDestroy();
+ int64_t m_timeOffset;
- // Shutdown bgfx.
- bgfx::shutdown();
+ NVGcontext* m_nvg;
+ DemoData m_data;
+};
- return 0;
-}
+ENTRY_IMPLEMENT_MAIN(ExampleNanoVG);