-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewcore2.cpp
More file actions
990 lines (714 loc) · 27.1 KB
/
newcore2.cpp
File metadata and controls
990 lines (714 loc) · 27.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
// newcore2.cpp : Questo file contiene la funzione 'main', in cui inizia e termina l'esecuzione del programma.
#pragma warning(disable:6386)
#pragma warning(disable:26451)
#define _CRT_SECURE_NO_WARNINGS
////////////////////////////////////////////////////////////////////////////////////
// include directories
#define STB_IMAGE_IMPLEMENTATION
#define STBI_FAILURE_USERMSG
#include <vml4.0/libs/stb/stb_image.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <vml4.0/libs/stb/stb_image_write.h>
#include <vml4.0/opengl/gui/foundation/common.h>
#include <vml4.0/opengl/gui/foundation/logger.h>
#include <vml4.0/opengl/gui/foundation/globalpaths.h>
#include <vml4.0/opengl/gui/foundation/mathutils.h>
#include <vml4.0/opengl/gui/foundation/glwindow.h>
#include <vml4.0/opengl/gui/foundation/view.h>
#include <vml4.0/opengl/gui/foundation/shader.h>
#include <vml4.0/opengl/gui/foundation/rgbutils.h>
#include <vml4.0/opengl/gui/foundation/texture.h>
#include <vml4.0/opengl/gui/foundation/fbo.h>
#include <vml4.0/libs/imgui-docking/imgui-docking/imgui.h>
#include <vml4.0/libs/imgui-docking/imgui-docking/imgui_internal.h>
#include <vml4.0/libs/imgui-docking/backends/imgui_impl_opengl3.h>
#include <vml4.0/libs/imgui-docking/backends/imgui_impl_glfw.h>
#include <vml4.0/libs/fontawesome/IconsFontAwesome6.h>
#include <vml4.0/opengl/gui/DebugLogWindow.h>
#include <vml4.0/opengl/gui/DebugTextureWindow.h>
#include <vml4.0/opengl/gui/leveleditor/level2dmap.h>
#include <vml4.0/opengl/gui/gui.h>
#include <vml4.0/libs/imgui-docking/addons/FIleDialog.h>
#include <vml4.0/opengl/gui/leveleditor/level2dpanel.h>
#include <vml4.0/opengl/gui/leveleditor/windowpopup.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// logger singleton
namespace vml
{
namespace utils
{
vml::utils::Logger* vml::utils::Logger::Singleton = nullptr;
}
}
// session singleton
namespace vml
{
namespace utils
{
vml::utils::GlobalPaths* vml::utils::GlobalPaths::Singleton = nullptr;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MyApp
{
private:
// -----------------------------------------------------------------------------
// private data
vml::OpenGLContextWindow* OpenGLContextWindow; // opengl context window
int NavMeshScalingFactor; // navigation mesh scaling factor
int NavMeshErosionFactor; // nacigation mesh erosion factor
glm::vec4 ClearColor; // background color
bool Saved;
fa2040::tools::Level2dPanel Level2dPanel;
ImGui::FileBrowser FileDialog;
WindowPopUp PopUp;
public:
// -----------------------------------------------------------------------------
// getters
bool IsUserNameValid() const { return !vml::utils::GlobalPaths::GetInstance()->GetUserName().empty(); }
bool IsMainProjectValid() const { return !vml::utils::GlobalPaths::GetInstance()->GetProjectPath().empty(); }
const std::string GettUserName() const { return vml::utils::GlobalPaths::GetInstance()->GetUserName(); }
const std::string GetProjectPath() const { return vml::utils::GlobalPaths::GetInstance()->GetProjectPath(); }
const std::string GetProjectName() const { return vml::utils::GlobalPaths::GetInstance()->GetProjectName(); }
const std::string GetFullProjectPath() const { return vml::utils::GlobalPaths::GetInstance()->GetFullProjectPath(); }
const std::string GetFullDebugPath() const { return vml::utils::GlobalPaths::GetInstance()->GetFullDebugPath(); }
const std::string GetProjectDir(const std::string& dir) const { return vml::utils::GlobalPaths::GetInstance()->GetProjectDir(dir); }
// -----------------------------------------------------------------------------
// init core
void Init()
{
// set preferences flags
vml::utils::Logger::GetInstance()->Init(vml::utils::Logger::LogMode::TO_MEM);
// log out that core has been initted correctly
vml::utils::Logger::GetInstance()->Info("Core : Initting Main : In progress");
// init global paths
vml::utils::GlobalPaths::GetInstance()->Init();
vml::utils::Logger::GetInstance()->Info("Core : Initting Global Paths : Done");
// log out that core has been initted correctly
vml::utils::Logger::GetInstance()->Info("Core : Initting Main : Done");
}
// -----------------------------------------------------------------------------------
// begin render state , starts with default values
void Begin() const
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Enable depth test
glEnable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
// Cull triangles whose normal is not towards the camera
glEnable(GL_CULL_FACE);
// sets ccw face
glFrontFace(GL_CCW);
// unbind any texture
glBindTexture(GL_TEXTURE_2D, 0);
// unbind any texture 2d array
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
// disable blending
glDisable(GL_BLEND);
// ubind texture sampler
glBindSampler(GL_TEXTURE0, 0);
// set clear color
glClearColor(ClearColor.r, ClearColor.g, ClearColor.b, ClearColor.w);
// Clear required buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// no shaders
glUseProgram(0);
}
// -----------------------------------------------------------------------------------
// set default render states back
void End() const
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Enable depth test
glDisable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
// Cull triangles whose normal is not towards the camera
glDisable(GL_CULL_FACE);
// unbind any texture
glBindTexture(GL_TEXTURE_2D, 0);
// unbind any texture 2d array
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
// disable blending
glDisable(GL_BLEND);
// no shaders
glUseProgram(0);
// flush
glFlush();
}
// -----------------------------------------------------------------------------
// closes Core
void Close()
{
// log closes by itself in its destructor
vml::utils::Logger::GetInstance()->Info("Core : Shutting Down Main : In progress");
// close opengl context
vml::os::SafeDelete(OpenGLContextWindow);
vml::utils::Logger::GetInstance()->Info("Core : Closing OpenglContext Winodw : Done");
// close global paths singleton
vml::utils::GlobalPaths::GetInstance()->Close();
vml::utils::Logger::GetInstance()->Info("Core : Shutting Down GlobalPaths : Done");
// log out results
vml::utils::Logger::GetInstance()->Info("Core : Shutting Down Main : Done");
// close logger
vml::utils::Logger::GetInstance()->Close();
}
// -----------------------------------------------------------------------------
// set wrking directory and paths
void SetProjectPath(const std::string& mainpath) const
{
vml::utils::GlobalPaths::GetInstance()->SetProjectPath(mainpath);
}
// -----------------------------------------------------------------------------
// set project name
void SetProjectName(const std::string& projectname) const
{
vml::utils::GlobalPaths::GetInstance()->SetProjectName(projectname);
}
// -----------------------------------------------------------------------------
// create projectdir
void CreateProjectDirs(const std::vector<std::string>& paths) const
{
vml::utils::GlobalPaths::GetInstance()->CreateProjectDirs(paths);
}
// -----------------------------------------------------------------------------
// sets name for current user
void SetCurrentUserName(const std::string& name) const
{
vml::utils::GlobalPaths::GetInstance()->SetCurrentUserName(name);
}
// -----------------------------------------------------------
// initting rendering context
void InitGLWindow(int width, int height, const std::string& title, unsigned int flags)
{
OpenGLContextWindow = new vml::OpenGLContextWindow();
OpenGLContextWindow->Init(width, height, title, flags);
}
// -----------------------------------------------------------
// rendering context functions
__forceinline void SwapBuffers() const { OpenGLContextWindow->SwapBuffers(); }
__forceinline void PollEvents() const { OpenGLContextWindow->PollEvents(); }
__forceinline void SetWindowTitle(const std::string& str) const { OpenGLContextWindow->SetWindowTitle(str); }
__forceinline void InitEvents() const { OpenGLContextWindow->InitEvents(); }
__forceinline bool IsWindowRunning() const { return OpenGLContextWindow->IsRunning(); }
__forceinline GLFWwindow* GetGLFWindow() const { return OpenGLContextWindow->GetWindow(); }
__forceinline vml::OpenGLContextWindow* GetOpenGLContextWindow() const { return OpenGLContextWindow; }
private:
// -------------------------------------------------------------
void ClearAll()
{
Level2dMap->Clear();
Level2dPanel.InitData(Level2dMap);
}
// -------------------------------------------------------------
void CompileMap()
{
Level2dMap->CompileMap(NavMeshScalingFactor, NavMeshErosionFactor);
Level2dPanel.InitData(Level2dMap);
}
// ----------------------------------------------------------------------
//
void SaveMap()
{
Level2dMap->Level2dGenerator->Convert2dMapTo3dFileAndSave(GetFullProjectPath());
Saved = true;
}
// ----------------------------------------------------------------------
//
void ToolBar()
{
ImVec4 enabled;
ImVec4 disabled;
enabled.x = 0.67f;
enabled.y = 0.67f;
enabled.z = 0.67f;
enabled.w = 0.39f;
disabled.x = 0.1f;
disabled.y = 0.1f;
disabled.z = 0.1f;
disabled.w = 1.0f;
bool levelcompiled = false;
if (Level2dMap->Level2dGenerator)
if (Level2dMap->Level2dGenerator->IsCompiled()) levelcompiled = true;
// show main triangelayer
if (Level2dMap->TextureVisible)
ImGui::PushStyleColor(ImGuiCol_Button, enabled);
else
ImGui::PushStyleColor(ImGuiCol_Button, disabled);
ImGui::PushID(0);
if (ImGui::Button(ICON_FA_IMAGE))
Level2dMap->TextureVisible ^= 1;
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("Show Texture");
ImGui::PopID();
ImGui::PopStyleColor(1);
ImGui::SameLine();
// show main triangelayer
if (Level2dMap->TriangleLayerVisible)
ImGui::PushStyleColor(ImGuiCol_Button, enabled);
else
ImGui::PushStyleColor(ImGuiCol_Button, disabled);
ImGui::PushID(1);
if (levelcompiled)
{
if (ImGui::Button(ICON_FA_VECTOR_SQUARE))
Level2dMap->TriangleLayerVisible ^= 1;
}
else
{
ImGui::BeginDisabled();
if (ImGui::Button(ICON_FA_VECTOR_SQUARE))
Level2dMap->TriangleLayerVisible ^= 1;
ImGui::EndDisabled();
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("Show Body Mesh");
ImGui::PopID();
ImGui::PopStyleColor(1);
ImGui::SameLine();
// show collision triangelayer
if (Level2dMap->BorderTriangleLayerVisible)
ImGui::PushStyleColor(ImGuiCol_Button, enabled);
else
ImGui::PushStyleColor(ImGuiCol_Button, disabled);
ImGui::PushID(2);
if (levelcompiled)
{
if (ImGui::Button(ICON_FA_OBJECT_UNGROUP))
Level2dMap->BorderTriangleLayerVisible ^= 1;
}
else
{
ImGui::BeginDisabled();
if (ImGui::Button(ICON_FA_OBJECT_UNGROUP))
Level2dMap->BorderTriangleLayerVisible ^= 1;
ImGui::EndDisabled();
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("Show Collision Mesh");
ImGui::PopID();
ImGui::PopStyleColor(1);
ImGui::SameLine();
// show nav triangelayer
if (Level2dMap->ExternalTriangleLayerVisible)
ImGui::PushStyleColor(ImGuiCol_Button, enabled);
else
ImGui::PushStyleColor(ImGuiCol_Button, disabled);
ImGui::PushID(3);
if (levelcompiled)
{
if (ImGui::Button(ICON_FA_ROUTE))
Level2dMap->ExternalTriangleLayerVisible ^= 1;
}
else
{
ImGui::BeginDisabled();
if (ImGui::Button(ICON_FA_ROUTE))
Level2dMap->ExternalTriangleLayerVisible ^= 1;
ImGui::EndDisabled();
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("Show Nav Mesh");
ImGui::PopID();
ImGui::PopStyleColor(1);
ImGui::SameLine();
// vertical separator
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(155.0f / 255.0f, 155.0f / 255.0f, 155.0f / 255.0f, 1.0f));
ImGui::Text("|");
ImGui::PopStyleColor();
ImGui::SameLine();
if (ImGui::Button(ICON_FA_ARROWS_TO_DOT))
Level2dMap->Reset();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("Reset Position");
}
// -----------------------------------------------------------
//
void MenuBar()
{
static bool opt_fullscreen = true;
static bool opt_padding = false;
static bool p_open = false;
bool levelcompiled = false;
if (Level2dMap->Level2dGenerator)
if (Level2dMap->Level2dGenerator->IsCompiled()) levelcompiled = true;
bool textureloaded = false;
if (Level2dMap->IsTextureLoaded())
textureloaded = true;
if (ImGui::BeginMenuBar())
{
// file option
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Load Texture", 0))
{
// std::cout << "texture loaded : " << textureloaded << std::endl;
// std::cout << "level compiled : " << levelcompiled << std::endl;
// std::cout << "level saved : " << Saved << std::endl;
if (!textureloaded || !levelcompiled || Saved)
{
FileDialog.Open();
}
else
{
PopUp.ShowWPopUp = true;
PopUp.PopUpString = "Save compiled mesh before loading a new image";
}
}
if (ImGui::MenuItem("Save Mesh", 0))
{
if (textureloaded)
{
if (levelcompiled)
{
SaveMap();
}
else
{
PopUp.ShowWPopUp = true;
PopUp.PopUpString = "Compile Image before saving";
}
}
else
{
PopUp.ShowWPopUp = true;
PopUp.PopUpString = "No Texture Loaded";
}
}
ImGui::EndMenu();
}
// compiling option
if (ImGui::BeginMenu("Compiling"))
{
if (ImGui::MenuItem("Generate 2d Triangle Layers", 0))
{
if (textureloaded)
{
if (!levelcompiled)
{
CompileMap();
}
else
{
PopUp.ShowWPopUp = true;
PopUp.PopUpString = "Map already compiled";
}
}
else
{
PopUp.ShowWPopUp = true;
PopUp.PopUpString = "No Texture Loaded";
}
}
ImGui::Separator();
if (ImGui::MenuItem("Clear All", 0))
{
ClearAll();
}
ImGui::EndMenu();
}
// preferences option
if (ImGui::BeginMenu("Preferences"))
{
if (ImGui::MenuItem("Show Texture", 0, Level2dMap->TextureVisible == 1))
{
Level2dMap->TextureVisible ^= 1;
}
if (ImGui::MenuItem("Show MainTriangle List", 0,Level2dMap->TriangleLayerVisible==1))
{
Level2dMap->TriangleLayerVisible ^= 1;
}
if (ImGui::MenuItem("Show BorderTriangle List", 0,Level2dMap->BorderTriangleLayerVisible==1))
{
Level2dMap->BorderTriangleLayerVisible ^= 1;
}
if (ImGui::MenuItem("Show ExternalTriangle List", 0,Level2dMap->ExternalTriangleLayerVisible==1))
{
Level2dMap->ExternalTriangleLayerVisible ^= 1;
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
}
public:
// -------------------------------------------------------------
vml::gui::GUI* Gui;
fa2040::tools::Level2dMap* Level2dMap;
vml::debugrendering::FrameBuffer* OpenglFBO;
// -------------------------------------------------------------
//
void LoadResources()
{
if (!GetOpenGLContextWindow())
vml::os::Message::Error("Core : Rendering Context not Initted");
Gui = new vml::gui::GUI();
ClearColor = glm::vec4(0, 0, 0.1f, 1.0f);
// leveldmap creation
Level2dMap = new fa2040::tools::Level2dMap();
Level2dMap->Init();
Level2dMap->LoadTexture(vml::utils::GlobalPaths::GetInstance()->GetFullProjectPath()+"\\textures\\"+"skull.bmp");
// Level2dMap->CompileAndSaveMap(NavMeshScalingFactor, NavMeshErosionFactor);
// create opengl fbo
OpenglFBO = new vml::debugrendering::FrameBuffer();
// Set file dialog properties
FileDialog.SetTitle("Load Bmp File");
FileDialog.SetTypeFilters({ ".bmp" });
}
// -----------------------------------------------------------
//
void DisposeResources()
{
vml::os::SafeDelete(Gui);
vml::os::SafeDelete(Level2dMap);
vml::os::SafeDelete(OpenglFBO);
}
// -----------------------------------------------------------
//
void KeyBindings() const
{
GLFWwindow* glwindow = GetOpenGLContextWindow()->GetWindow();
if (glfwGetKeyOnce(glwindow, GLFW_KEY_Q))
{
// PopUp.ShowWPopUp = true;
// PopUp.PopUpString = "Save compiled mesh before loading a new image";
}
if (glfwGetKey(glwindow, GLFW_KEY_UP))
{
}
if (glfwGetKey(glwindow, GLFW_KEY_DOWN))
{
}
if (glfwGetKey(glwindow, GLFW_KEY_LEFT))
{
}
if (glfwGetKey(glwindow, GLFW_KEY_RIGHT))
{
}
if (glfwGetKey(glwindow, GLFW_KEY_PAGE_UP))
{
}
if (glfwGetKey(glwindow, GLFW_KEY_PAGE_DOWN))
{
}
}
// ---------------------------------------------------------------
void Draw2d(const int window_width, const int window_height, const int window_bminx, const int window_bminy)
{
// glm::vec4 col0 = glm::vec4(0.1f, 0.1f, 0.1f, 1);
// glm::vec4 col1 = col0;
// glm::vec4 col2 = col0 * 1.5f;
// vml::debugrendering::DebugMaterial material00(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // ambient
// glm::vec4(0.5f, 0.5f, 0.5f, 1.0f), // diffuse
// glm::vec4(0.6f, 0.6f, 0.6f, 1.0f), // specular
// glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), // emission
// 2); // shininess
// update current view
vml::views::View* view = Level2dMap->View;
// update current view
view->UpdateView(window_width, window_height);
view->UpdateGlViewPort();
// init debug rendering
Begin();
Level2dMap->BeginOrtho();
Level2dMap->DrawLayers();
Level2dMap->DrawTexture();
Level2dMap->EndOrtho();
// GetOpenglDebugRender()->DrawCheckeredQuad(view, 100.0f, glm::vec3(0, 0, 0), 32, col1, col2, material00);
// vml::debugrendering::OpenglDebugRender2* ogldb = GetOpenglDebugRender();
// glm::vec4 color = glm::vec4(0, 0, 0.3f, 1.0f);
// for ( float y=-100; y<100; y+=10)
// ogldb->DrawLine(view, glm::vec3(-100, 0, y), glm::vec3(100, 0, y), color,false);
// for (float x = -100; x < 100; x += 10)
// ogldb->DrawLine(view, glm::vec3(x, 0, -100), glm::vec3(x, 0,100), color, false);
// finished debug rendeirng
End();
}
// -----------------------------------------------------------
//
void DrawDock()
{
// begin dear imgui rendering
Gui->BeginFrame();
// docking stuff
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_AutoHideTabBar;
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
// because it would be confusing to have two docking targets within each others.
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
// When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background.
if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode)
window_flags |= ImGuiWindowFlags_NoBackground;
// Important: note that we proceed even if Begin() returns false (aka window is collapsed).
// This is because we want to keep our DockSpace() active. If a DockSpace() is inactive,
// all active windows docked into it will lose their parent and become undocked.
// We cannot preserve the docking relationship between an active window and an inactive docking, otherwise
// any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("DockSpace", nullptr, window_flags);
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
// DockSpace
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
static bool first_time = true;
if (first_time)
{
first_time = false;
ImGui::DockBuilderRemoveNode(dockspace_id); // clear any previous layout
ImGui::DockBuilderAddNode(dockspace_id, dockspace_flags | ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
// split the dockspace into 2 nodes -- DockBuilderSplitNode takes in the following args in the following order
// window ID to split, direction, fraction (between 0 and 1), the final two setting let's us choose which id we want
// (which ever one we DON'T set as NULL, will be returned by the function)
// out_id_at_dir is the id of the node in the direction we specified earlier, out_id_at_opposite_dir is in the opposite direction
ImGuiID dock_main_id = dockspace_id;
ImGuiID dock_left_id = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Left, 0.2f, nullptr, &dock_main_id);
ImGuiID dock_down_id = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Down, 0.3f, nullptr, &dock_main_id);
ImGui::DockBuilderDockWindow("Window 0", dock_main_id);
ImGui::DockBuilderDockWindow("Window 1", dock_left_id);
ImGui::DockBuilderDockWindow("Window 2", dock_down_id);
// finalize docking
ImGui::DockBuilderFinish(dockspace_id);
}
}
// menu bar
MenuBar();
// end docking rednering
ImGui::End();
//
ImGui::Begin("Window 0");
ToolBar();
// windo is updated only if moved by title
io.ConfigWindowsMoveFromTitleBarOnly = 1;
const float window_width = ImGui::GetContentRegionAvail().x;
const float window_height = ImGui::GetContentRegionAvail().y;
// rescale fbo to fit imgui window
OpenglFBO->RescaleFrameBuffer(window_width, window_height);
// update view only if mouse is in context window
ImVec2 window_bmin(ImGui::GetCursorScreenPos().x, ImGui::GetCursorScreenPos().y);
ImVec2 window_bmax(window_bmin.x + window_width, window_bmin.y + window_height);
ImVec2 mpos(io.MousePos.x, io.MousePos.y);
if (ImGui::IsWindowHovered(ImGuiFocusedFlags_RootWindow))
{
if (mpos.x >= window_bmin.x && mpos.x <= window_bmax.x)
{
if (mpos.y >= window_bmin.y && mpos.y <= window_bmax.y)
{
Level2dMap->UpdateInput(GetOpenGLContextWindow());
}
}
}
// add image of rendered view to imgui image using window extents
ImGui::GetWindowDrawList()->AddImage((ImTextureID)static_cast<uintptr_t>(OpenglFBO->getFrameTexture()),
window_bmin,
window_bmax,
ImVec2(0, 1),
ImVec2(1, 0));
// end windows
ImGui::End();
// rednder into custom fbo
OpenglFBO->Bind();
// redner 2d editor
Draw2d(window_width, window_height, window_bmin.x, window_bmin.y);
// stop rednering into the custom fbo
OpenglFBO->Unbind();
// editor window
Level2dPanel.Draw("Window 1",Level2dMap);
// log window
ImGui::Begin("Window 2");
Gui->DbgLog.Draw();
ImGui::End();
// file loading
FileDialog.Display();
if (FileDialog.HasSelected())
{
// std::cout << "Selected filename" << FileDialog.GetSelected().string() << std::endl;
vml::utils::Logger::GetInstance()->Info("Level Editor", "Loading file" + FileDialog.GetSelected().string());
Level2dMap->LoadTexture(FileDialog.GetSelected().string());
Level2dMap->Reset();
FileDialog.ClearSelected();
Saved = false;
}
// show modal popup
// pop up opens when ShowPopUp flag inside the cla<ss is set to true
PopUp.ShowWarningPopUp();
PopUp.ShowQuestionPopUp();
if (PopUp.QResult)
{
std::cout << "Qresult" << PopUp.QResult << std::endl;
}
// redner dear imgui
Gui->RenderFrame();
}
// -------------------------------------------------------------
MyApp()
{
Gui = nullptr;
Level2dMap = nullptr;
OpenglFBO = nullptr;
Saved = false;
NavMeshScalingFactor = 8;
NavMeshErosionFactor = 2;
OpenGLContextWindow = nullptr;
ClearColor = glm::vec4(1, 0, 0, 1);
}
~MyApp()
{
}
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_REPORT_FLAG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
MyApp* app = new MyApp();
app->Init();
app->SetCurrentUserName("Davide Cleoapdre");
app->SetProjectPath("C:\\vml4.0\\content");
app->SetProjectName("fa2040");
app->CreateProjectDirs({ "icons","fonts","meshes","textures","shaders","sounds","source","levels"});
app->InitGLWindow(1024, 768, "Tutorial01", vml::OpenGLContextWindow::WINDOWED | vml::OpenGLContextWindow::MAXIMIZED | vml::OpenGLContextWindow::OPENGL_4_0);
app->LoadResources();
app->Gui->InitDearImGui(app->GetOpenGLContextWindow());
// main renering loop
while (app->IsWindowRunning())
{
app->InitEvents();
app->Begin();
app->KeyBindings();
app->DrawDock();
app->End();
// swap buffers
app->SwapBuffers();
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
app->PollEvents();
}
// close dear imgui
app->Gui->CloseDearImGui();
// dispose resources
app->DisposeResources();
// close app
app->Close();
// delete app
vml::os::SafeDelete(app);
// print log
// std::cout << vml::strings::StringUtils::LoadText("log.txt") << std::endl;
// report leaks ( if any )
_CrtDumpMemoryLeaks();
}