951 {
952
953 srand((unsigned int)time(NULL));
954
955 SetUpIcon();
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";
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 + "\"";
1006 appState->mainMenu =
new MainMenu(appState);
1007 appState->seaManager =
new SeaManager(appState);
1009 appState->skyManager =
new SkyManager(appState);
1012 appState->serailizer =
new Serializer(appState);
1013 appState->osLiscences =
new OSLiscences(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));
1035 float t = 1.0f;
1036
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
1041 appState->frameBuffers.reflection =
new FrameBuffer();
1042
1043 appState->frameBuffers.main =
new FrameBuffer(1280, 720);
1044
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;
1070 Log("Started Up App!");
1071 }