TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ OnStart()

virtual void MyApp::OnStart ( std::string  loadFile)
inlineoverridevirtual

Reimplemented from Application.

Definition at line 950 of file Main.cpp.

951 {
952 // Set random generator seed from current time
953 srand((unsigned int)time(NULL));
954 // Setup custom icon for the Main Window
955 SetUpIcon();
956 appState = new ApplicationState();
957 appState->mainApp = mainApp;
958 appState->constants.executableDir = GetExecutableDir();
959 appState->constants.dataDir = appState->constants.executableDir + PATH_SEPARATOR "Data";
960 appState->constants.cacheDir = appState->constants.dataDir + PATH_SEPARATOR "cache";
961 appState->constants.texturesDir = appState->constants.dataDir + PATH_SEPARATOR "textures";
962 appState->constants.projectsDir = appState->constants.cacheDir + PATH_SEPARATOR "project_data";
963 appState->constants.tempDir = appState->constants.dataDir + PATH_SEPARATOR "temp";
964 appState->constants.shadersDir = appState->constants.dataDir + PATH_SEPARATOR "shaders";
965 appState->constants.kernelsDir = appState->constants.dataDir + PATH_SEPARATOR "kernels";
966 appState->constants.fontsDir = appState->constants.dataDir + PATH_SEPARATOR "fonts";
967 appState->constants.liscensesDir = appState->constants.dataDir + PATH_SEPARATOR "licenses";
968 appState->constants.skyboxDir = appState->constants.dataDir + PATH_SEPARATOR "skybox";
969 appState->constants.modulesDir = appState->constants.dataDir + PATH_SEPARATOR "modules";
970 appState->constants.configsDir = appState->constants.dataDir + PATH_SEPARATOR "configs";
971 appState->constants.logsDir = appState->constants.dataDir + PATH_SEPARATOR "logs";
972 appState->constants.modelsDir = appState->constants.dataDir + PATH_SEPARATOR "models";
973 appState->supportersTribute = new SupportersTribute();
974 SetupExplorerControls();
975 ImGui::GetStyle().WindowMenuButtonPosition = ImGuiDir_None;
976 LoadDefaultStyle();
977 GetWindow()->SetShouldCloseCallback(OnAppClose);
978 glfwSetFramebufferSizeCallback(GetWindow()->GetNativeWindow(), [](GLFWwindow* window, int w, int h)
979 {
980 glfwSwapBuffers(window);
981 });
982 glfwSetScrollCallback(GetWindow()->GetNativeWindow(), [](GLFWwindow *, double x, double y)
983 {
984 ImGuiIO &io = ImGui::GetIO();
985 io.MouseWheel = (float)y;
986 });
987 glfwSetDropCallback(GetWindow()->GetNativeWindow(), [](GLFWwindow *, int count, const char ** paths)
988 {
989 for (int i = 0; i < count; i++)
990 {
991 std::string path = paths[i];
992 if (path.find(".terr3d") != std::string::npos)
993 {
994 appState->serailizer->LoadFile(path);
995 }
996 else if(path.find(".terr3dpack") != std::string::npos)
997 {
998 appState->serailizer->LoadPackedProject(path);
999 }
1000 }
1001 });
1002 GetWindow()->SetClearColor({ 0.1f, 0.1f, 0.1f });
1003 appState->globals.kernelsIncludeDir = "\""+ appState->constants.kernelsDir + "\"";
1004 appState->modules.manager = new ModuleManager(appState);
1005 appState->meshGenerator = new MeshGeneratorManager(appState);
1006 appState->mainMenu = new MainMenu(appState);
1007 appState->seaManager = new SeaManager(appState);
1008 appState->lightManager = new LightManager();
1009 appState->skyManager = new SkyManager(appState);
1010 appState->foliageManager = new FoliageManager(appState);
1011 appState->projectManager = new ProjectManager(appState);
1012 appState->serailizer = new Serializer(appState);
1013 appState->osLiscences = new OSLiscences(appState);
1014 appState->textureStore = new TextureStore(appState);
1015 appState->shadingManager = new ShadingManager(appState);
1016 appState->textureBaker = new TextureBaker(appState);
1017 ResetShader();
1018 appState->meshGenerator->GenerateSync();
1019 appState->models.coreTerrain->SetupMeshOnGPU();
1020 appState->models.screenQuad->SetupMeshOnGPU();
1021 appState->models.screenQuad->mesh->GenerateScreenQuad();
1022 appState->models.screenQuad->mesh->RecalculateNormals();
1023 appState->models.screenQuad->UploadToGPU();
1024 glEnable(GL_DEPTH_TEST);
1025 appState->globals.scale = 1;
1026
1027 if (loadFile.size() > 0)
1028 {
1029 Log("Loading File from " + loadFile);
1030 OpenSaveFile(loadFile);
1031 }
1032
1033 appState->projectManager->SetId(GenerateId(32));
1034 appState->filtersManager = new FiltersManager(appState);
1035 float t = 1.0f;
1036 // Load Fonts
1037 LoadUIFont("Open-Sans-Regular", 18, appState->constants.fontsDir + PATH_SEPARATOR "OpenSans-Regular.ttf");
1038 LoadUIFont("OpenSans-Bold", 25, appState->constants.fontsDir + PATH_SEPARATOR "OpenSans-Bold.ttf");
1039 LoadUIFont("OpenSans-Semi-Bold", 22, appState->constants.fontsDir + PATH_SEPARATOR "OpenSans-Bold.ttf");
1040 // The framebuffer used for reflections in the sea
1041 appState->frameBuffers.reflection = new FrameBuffer();
1042 // The main frame buffer
1043 appState->frameBuffers.main = new FrameBuffer(1280, 720);
1044 // The Framebuffer used for post processing
1045 appState->frameBuffers.postProcess = new FrameBuffer(1280, 720);
1046 bool tpp = false;
1047 appState->shaders.postProcess = new Shader(ReadShaderSourceFile(appState->constants.shadersDir + PATH_SEPARATOR "post_processing" PATH_SEPARATOR "vert.glsl", &tpp),
1048 ReadShaderSourceFile(appState->constants.shadersDir + PATH_SEPARATOR "post_processing" PATH_SEPARATOR "frag.glsl", &tpp));
1049 appState->states.autoUpdate = true;
1050
1051 if(IsNetWorkConnected())
1052 {
1053 if(FileExists(appState->constants.configsDir + PATH_SEPARATOR "server.terr3d"))
1054 {
1055 bool ttmp = false;
1056 std::string uid = ReadShaderSourceFile(appState->constants.configsDir + PATH_SEPARATOR "server.terr3d", &ttmp);
1057 Log("Connection to Backend : " + FetchURL("https://terraforge3d.maxalpha.repl.co", "/startup/" + uid));
1058 }
1059
1060 else
1061 {
1062 DownloadFile("https://terraforge3d.maxalpha.repl.co", "/register", appState->constants.configsDir + PATH_SEPARATOR "server.terr3d");
1063 bool ttmp = false;
1064 std::string uid = ReadShaderSourceFile(appState->constants.configsDir + PATH_SEPARATOR "server.terr3d", &ttmp);
1065 Log("Connection to Backend : " + FetchURL("https://terraforge3d.maxalpha.repl.co", "/startup/" + uid));
1066 }
1067 }
1068
1069 appState->windows.shadingManager = true; // TEMPORARY FOR DEBUG ONLY
1070 Log("Started Up App!");
1071 }
Definition: Shader.h:7