Created
May 26, 2017 08:40
-
-
Save attilaz/410a4543020da4de11c62c00ec098c77 to your computer and use it in GitHub Desktop.
bgfx mega example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| in examples like hdr.cpp: | |
| #ifndef SKIP_ENTRY_IMPLEMENT_MAIN | |
| ENTRY_IMPLEMENT_MAIN(ExampleHDR); | |
| #endif | |
| ---------------------------------------------------------------------- | |
| in mega.cpp: | |
| /* | |
| * Copyright 2011-2017 Branimir Karadzic. All rights reserved. | |
| * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause | |
| */ | |
| #include <bx/uint32_t.h> | |
| #include "common.h" | |
| #include "bgfx_utils.h" | |
| #include <imgui/imgui.h> | |
| #define SKIP_ENTRY_IMPLEMENT_MAIN | |
| #include "../09-hdr/hdr.cpp" | |
| #include "../33-pom/pom.cpp" | |
| #undef SKIP_ENTRY_IMPLEMENT_MAIN | |
| #define EXAMPLE_ENTRY_IMPLEMENT_MAIN(_app) \ | |
| if ( ImGui::Button(#_app) ) \ | |
| {\ | |
| shutdown(); \ | |
| _app app; \ | |
| entry::runApp(&app, 0, NULL); \ | |
| } | |
| class ExampleMega : public entry::AppI | |
| { | |
| void init(int _argc, char** _argv) BX_OVERRIDE | |
| { | |
| Args args(_argc, _argv); | |
| 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(m_width, m_height, m_reset); | |
| imguiCreate(); | |
| // 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 | |
| ); | |
| } | |
| virtual int shutdown() BX_OVERRIDE | |
| { | |
| imguiDestroy(); | |
| // Shutdown bgfx. | |
| bgfx::shutdown(); | |
| return 0; | |
| } | |
| bool update() BX_OVERRIDE | |
| { | |
| if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) ) | |
| { | |
| // Set view 0 default viewport. | |
| bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(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); | |
| // Use debug font to print information about this example. | |
| bgfx::dbgTextClear(); | |
| bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/99-mega"); | |
| bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Example starter screen"); | |
| 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) | |
| ); | |
| ImGui::Begin("Examples"); | |
| ImGui::SetWindowPos(ImVec2(20.0f, 100.0f)); | |
| EXAMPLE_ENTRY_IMPLEMENT_MAIN(ExamplePom); | |
| EXAMPLE_ENTRY_IMPLEMENT_MAIN(ExampleHDR); | |
| ImGui::End(); | |
| imguiEndFrame(); | |
| // Advance to next frame. Rendering thread will be kicked to | |
| // process submitted rendering primitives. | |
| bgfx::frame(); | |
| return true; | |
| } | |
| return false; | |
| } | |
| entry::MouseState m_mouseState; | |
| uint32_t m_width; | |
| uint32_t m_height; | |
| uint32_t m_debug; | |
| uint32_t m_reset; | |
| }; | |
| ENTRY_IMPLEMENT_MAIN(ExampleMega); | |
| ----------------------------------------------------------- | |
| error: | |
| 's_cubeVertices' : redefinition; different subscripts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment