mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-18 04:53:06 +01:00
Combined all examples. Issue #1143.
This commit is contained in:
@@ -9,9 +9,13 @@
|
||||
#include <entry/input.h>
|
||||
#include <debugdraw/debugdraw.h>
|
||||
#include "camera.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#include <bx/uint32_t.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void imageCheckerboard(void* _dst, uint32_t _width, uint32_t _height, uint32_t _step, uint32_t _0, uint32_t _1)
|
||||
{
|
||||
uint32_t* dst = (uint32_t*)_dst;
|
||||
@@ -25,15 +29,21 @@ void imageCheckerboard(void* _dst, uint32_t _width, uint32_t _height, uint32_t _
|
||||
}
|
||||
}
|
||||
|
||||
class DebugDrawApp : public entry::AppI
|
||||
class ExampleDebugDraw : public entry::AppI
|
||||
{
|
||||
public:
|
||||
ExampleDebugDraw(const char* _name, const char* _description)
|
||||
: entry::AppI(_name, _description)
|
||||
{
|
||||
}
|
||||
|
||||
void init(int _argc, char** _argv) BX_OVERRIDE
|
||||
{
|
||||
Args args(_argc, _argv);
|
||||
|
||||
m_width = 1280;
|
||||
m_height = 720;
|
||||
m_debug = BGFX_DEBUG_TEXT;
|
||||
m_debug = BGFX_DEBUG_NONE;
|
||||
m_reset = BGFX_RESET_VSYNC | BGFX_RESET_MSAA_X16;
|
||||
|
||||
bgfx::init(args.m_type, args.m_pciId);
|
||||
@@ -64,10 +74,14 @@ class DebugDrawApp : public entry::AppI
|
||||
imageCheckerboard(data, 32, 32, 4, 0xff808080, 0xffc0c0c0);
|
||||
|
||||
m_sprite = ddCreateSprite(32, 32, data);
|
||||
|
||||
imguiCreate();
|
||||
}
|
||||
|
||||
virtual int shutdown() BX_OVERRIDE
|
||||
{
|
||||
imguiDestroy();
|
||||
|
||||
ddDestroy(m_sprite);
|
||||
|
||||
ddShutdown();
|
||||
@@ -84,20 +98,27 @@ class DebugDrawApp : public entry::AppI
|
||||
{
|
||||
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
|
||||
{
|
||||
imguiBeginFrame(m_mouseState.m_mx
|
||||
, m_mouseState.m_my
|
||||
, (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
|
||||
| (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
|
||||
| (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
|
||||
, m_mouseState.m_mz
|
||||
, uint16_t(m_width)
|
||||
, uint16_t(m_height)
|
||||
);
|
||||
|
||||
bool restart = showExampleDialog(this);
|
||||
|
||||
imguiEndFrame();
|
||||
|
||||
int64_t now = bx::getHPCounter() - m_timeOffset;
|
||||
static int64_t last = now;
|
||||
const int64_t frameTime = now - last;
|
||||
last = now;
|
||||
const double freq = double(bx::getHPFrequency() );
|
||||
const double toMs = 1000.0/freq;
|
||||
const float deltaTime = float(frameTime/freq);
|
||||
|
||||
// Use debug font to print information about this example.
|
||||
bgfx::dbgTextClear();
|
||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/29-debugdraw");
|
||||
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Debug draw.");
|
||||
bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
||||
|
||||
// Update camera.
|
||||
cameraUpdate(deltaTime, m_mouseState);
|
||||
|
||||
@@ -269,7 +290,7 @@ class DebugDrawApp : public entry::AppI
|
||||
// process submitted rendering primitives.
|
||||
bgfx::frame();
|
||||
|
||||
return true;
|
||||
return !restart;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -286,4 +307,6 @@ class DebugDrawApp : public entry::AppI
|
||||
uint32_t m_reset;
|
||||
};
|
||||
|
||||
ENTRY_IMPLEMENT_MAIN(DebugDrawApp);
|
||||
} // namespace
|
||||
|
||||
ENTRY_IMPLEMENT_MAIN(ExampleDebugDraw, "29-debugdraw", "Debug draw.");
|
||||
|
||||
Reference in New Issue
Block a user