|
3 | 3 | #include <Math/Array/OgreObjectMemoryManager.h>
|
4 | 4 | #include <OgreCommon.h>
|
5 | 5 | #include <OgreGpuResource.h>
|
6 |
| -#include <OgreImage2.h> |
7 | 6 | #include <OgreRoot.h>
|
8 |
| -#include <OgreTextureGpu.h> |
9 |
| -#include <OgreTextureGpuManager.h> |
10 | 7 | #include <OgreWindow.h>
|
11 | 8 | #include <SDL_events.h>
|
12 | 9 | #include <TutorialGameState.h>
|
|
21 | 18 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
22 | 19 | #define NK_INCLUDE_FONT_BAKING
|
23 | 20 | #define NK_INCLUDE_DEFAULT_FONT
|
24 |
| -#define NK_IMPLEMENTATION |
25 | 21 | #include <nuklear.h>
|
26 |
| -#include "NuklearOgre.h" |
| 22 | +#include <NuklearRenderer.h> |
27 | 23 |
|
28 | 24 | #include "../../Nuklear/demo/common/overview.c"
|
29 | 25 |
|
30 | 26 | #define GUI_RENDER_QUEUE_ID 200u
|
31 | 27 |
|
32 | 28 | namespace Demo
|
33 | 29 | {
|
34 |
| - void RegisterNuklearCompositor(Ogre::Root *root, NuklearOgre::NuklearRenderer *renderer) |
35 |
| - { |
36 |
| - NuklearOgre::RegisterCompositor(root, renderer); |
37 |
| - } |
38 |
| - |
39 | 30 | NuklearOgreGameState::NuklearOgreGameState(const Ogre::String &helpDescription)
|
40 | 31 | : TutorialGameState(helpDescription)
|
41 | 32 | {
|
42 | 33 |
|
43 | 34 | }
|
44 | 35 |
|
45 |
| - void nk_font_stash_begin(nk_font_atlas *atlas) |
46 |
| - { |
47 |
| - nk_font_atlas_init_default(atlas); |
48 |
| - nk_font_atlas_begin(atlas); |
49 |
| - } |
50 |
| - |
51 |
| - void nk_font_stash_end(nk_font_atlas *atlas, nk_context *ctx, |
52 |
| - Ogre::TextureGpuManager *textureManager, |
53 |
| - nk_draw_null_texture *texNull) |
54 |
| - { |
55 |
| - const void *image; int w, h; |
56 |
| - image = nk_font_atlas_bake(atlas, &w, &h, NK_FONT_ATLAS_RGBA32); |
57 |
| - |
58 |
| - Ogre::Image2 *imagePtr = new Ogre::Image2; |
59 |
| - imagePtr->loadDynamicImage(const_cast<void *>(image), w, h, 1, Ogre::TextureTypes::Type2D, Ogre::PFG_RGBA8_UNORM_SRGB, false, 1); |
60 |
| - |
61 |
| - Ogre::TextureGpu *texture = textureManager->createTexture("FontAtlas", Ogre::GpuPageOutStrategy::Discard, |
62 |
| - Ogre::TextureFlags::AutomaticBatching | |
63 |
| - Ogre::TextureFlags::PrefersLoadingFromFileAsSRGB, |
64 |
| - Ogre::TextureTypes::Type2D); |
65 |
| - texture->scheduleTransitionTo(Ogre::GpuResidency::Resident, imagePtr, true); |
66 |
| - |
67 |
| - nk_font_atlas_end(atlas, nk_handle_ptr(texture), texNull); |
68 |
| - |
69 |
| - if (atlas->default_font) |
70 |
| - nk_style_set_font(ctx, &atlas->default_font->handle); |
71 |
| - } |
72 |
| - |
73 | 36 | void NuklearOgreGameState::createScene01(void)
|
74 | 37 | {
|
75 |
| - mNuklearCtx.reset(new nk_context); |
76 |
| - mFontAtlas.reset(new nk_font_atlas); |
77 |
| - nk_init_default(mNuklearCtx.get(), 0); |
78 |
| - |
79 |
| - nk_convert_config config; |
80 |
| - memset(&config, 0, sizeof(config)); |
81 |
| - config.circle_segment_count = 22; |
82 |
| - config.curve_segment_count = 22; |
83 |
| - config.arc_segment_count = 22; |
84 |
| - config.global_alpha = 1.0f; |
85 |
| - config.shape_AA = NK_ANTI_ALIASING_OFF; |
86 |
| - config.line_AA = NK_ANTI_ALIASING_OFF; |
87 |
| - |
88 |
| - /* Load Fonts: if none of these are loaded a default font will be used */ |
89 |
| - /* Load Cursor: if you uncomment cursor loading please hide the cursor */ |
90 |
| - nk_font_atlas *atlas = mFontAtlas.get(); |
91 |
| - nk_font_stash_begin(atlas); |
92 |
| - /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ |
93 |
| - /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ |
94 |
| - /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ |
95 |
| - /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ |
96 |
| - /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ |
97 |
| - /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ |
98 |
| - nk_context *ctx = mNuklearCtx.get(); |
99 |
| - Ogre::TextureGpuManager *textureManager = mGraphicsSystem->getRoot()->getHlmsManager()->getRenderSystem()->getTextureGpuManager(); |
100 |
| - nk_font_stash_end(atlas, ctx, textureManager, &config.tex_null); |
101 |
| - /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ |
102 |
| - /*nk_style_set_font(ctx, &roboto->handle);*/ |
103 |
| - |
104 |
| - Ogre::SceneManager *sceneManager = mGraphicsSystem->getSceneManager(); |
105 |
| - Ogre::ObjectMemoryManager *memManager = &sceneManager->_getEntityMemoryManager(Ogre::SCENE_DYNAMIC); |
106 |
| - mNuklearOgre.reset(new NuklearOgre::NuklearOgre(mGraphicsSystem->getRoot(), mGraphicsSystem->getSceneManager(), config)); |
107 |
| - mNuklearOgre->addContext(mNuklearCtx.get()); |
108 |
| - |
109 | 38 | mCameraController = new CameraController( mGraphicsSystem, false );
|
110 | 39 |
|
111 | 40 | TutorialGameState::createScene01();
|
112 | 41 |
|
113 |
| - nk_input_begin(mNuklearCtx.get()); |
114 |
| - } |
115 |
| - |
116 |
| - void NuklearOgreGameState::destroyScene(void) |
117 |
| - { |
118 |
| - Ogre::SceneManager *sceneManager = mGraphicsSystem->getSceneManager(); |
119 |
| - sceneManager->getRootSceneNode(Ogre::SCENE_DYNAMIC)->removeAndDestroyAllChildren(); |
120 |
| - |
121 |
| - nk_font_atlas_clear(mFontAtlas.get()); |
122 |
| - nk_free(mNuklearCtx.get()); |
123 |
| - mNuklearCtx.reset(); |
124 |
| - mFontAtlas.reset(); |
125 |
| - mNuklearOgre.reset(); |
126 |
| - |
127 |
| - TutorialGameState::destroyScene(); |
128 |
| - } |
129 |
| - |
130 |
| - void NuklearOgreGameState::render(Ogre::SceneManager *sceneManager) |
131 |
| - { |
132 |
| - mNuklearOgre->render(sceneManager); |
| 42 | + nk_input_begin(mNuklearCtx); |
133 | 43 | }
|
134 | 44 |
|
135 | 45 | void NuklearOgreGameState::update(float timeSinceLast)
|
136 | 46 | {
|
137 |
| - nk_context *ctx = mNuklearCtx.get(); |
| 47 | + nk_context *ctx = mNuklearCtx; |
138 | 48 |
|
139 | 49 | nk_input_end(ctx);
|
140 | 50 |
|
@@ -182,7 +92,7 @@ namespace Demo
|
182 | 92 |
|
183 | 93 | void NuklearOgreGameState::mouseMoved(const SDL_Event &evt)
|
184 | 94 | {
|
185 |
| - nk_context *ctx = mNuklearCtx.get(); |
| 95 | + nk_context *ctx = mNuklearCtx; |
186 | 96 |
|
187 | 97 | if (evt.type == SDL_MOUSEMOTION)
|
188 | 98 | {
|
@@ -228,14 +138,14 @@ namespace Demo
|
228 | 138 |
|
229 | 139 | void NuklearOgreGameState::mousePressed(const SDL_MouseButtonEvent &button, Ogre::uint8 id)
|
230 | 140 | {
|
231 |
| - nk_context *ctx = mNuklearCtx.get(); |
| 141 | + nk_context *ctx = mNuklearCtx; |
232 | 142 | handleMouseButton(button, true, ctx);
|
233 | 143 |
|
234 | 144 | TutorialGameState::mousePressed(button, id);
|
235 | 145 | }
|
236 | 146 | void NuklearOgreGameState::mouseReleased(const SDL_MouseButtonEvent &button, Ogre::uint8 id)
|
237 | 147 | {
|
238 |
| - nk_context *ctx = mNuklearCtx.get(); |
| 148 | + nk_context *ctx = mNuklearCtx; |
239 | 149 | handleMouseButton(button, false, ctx);
|
240 | 150 |
|
241 | 151 | TutorialGameState::mouseReleased(button, id);
|
|
0 commit comments