diff --git a/src/editor/BspRenderer.cpp b/src/editor/BspRenderer.cpp index 1760af24..a49941b0 100644 --- a/src/editor/BspRenderer.cpp +++ b/src/editor/BspRenderer.cpp @@ -65,30 +65,35 @@ BspRenderer::BspRenderer(Bsp* _map) { print_log(get_localized_string(LANG_0267)); Entity* foundEnt = NULL; + bool foundCam = false; + for (auto ent : map->ents) { - if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_start") + if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera") { + foundCam = true; foundEnt = ent; break; } } + if (!foundEnt) { for (auto ent : map->ents) { - if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_deathmatch") + if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_start") { foundEnt = ent; break; } } } + if (!foundEnt) { for (auto ent : map->ents) { - if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera") + if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_deathmatch") { foundEnt = ent; break; @@ -96,62 +101,30 @@ BspRenderer::BspRenderer(Bsp* _map) } } - - if (foundEnt) + if (!foundEnt) { - renderCameraOrigin = foundEnt->origin; - renderCameraOrigin.z += 32; - for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++) + for (auto ent : map->ents) { - if (foundEnt->keyOrder[i] == "angles") - { - renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]); - } - if (foundEnt->keyOrder[i] == "angle") - { - float y = str_to_float(foundEnt->keyvalues["angle"]); - - if (y >= 0.0f) - { - renderCameraAngles.y = y; - } - else if (y == -1.0f) - { - renderCameraAngles.x = -90.0f; - renderCameraAngles.y = 0.0f; - renderCameraAngles.z = 0.0f; - } - else if (y <= -2.0f) - { - renderCameraAngles.x = 90.0f; - renderCameraAngles.y = 0.0f; - renderCameraAngles.z = 0.0f; - } - } + foundEnt = ent; + break; } - - renderCameraAngles = renderCameraAngles.flip(); - renderCameraAngles.z = renderCameraAngles.z + 90.0f; - renderCameraAngles = renderCameraAngles.normalize_angles(); - renderCameraAngles.y = 0.0f; } - - /*for (auto ent : map->ents) + if (foundEnt) { - if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_start") + renderCameraOrigin = foundEnt->origin; + if (!foundCam) { - renderCameraOrigin = ent->origin; - - /*for (unsigned int i = 0; i < ent->keyOrder.size(); i++) + renderCameraOrigin.z += 32; + for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++) { - if (ent->keyOrder[i] == "angles") + if (foundEnt->keyOrder[i] == "angles") { - renderCameraAngles = parseVector(ent->keyvalues["angles"]); + renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]); } - if (ent->keyOrder[i] == "angle") + if (foundEnt->keyOrder[i] == "angle") { - float y = str_to_float(ent->keyvalues["angle"]); + float y = str_to_float(foundEnt->keyvalues["angle"]); if (y >= 0.0f) { @@ -171,39 +144,43 @@ BspRenderer::BspRenderer(Bsp* _map) } } } - - break; } -*/ - - -//if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera") -//{ -// this->renderCameraOrigin = ent->origin; - /* - auto targets = ent->getTargets(); - bool found = false; - for (auto ent2 : map->ents) - { - if (found) - break; - if (ent2->hasKey("targetname")) - { - for (auto target : targets) + else { - if (ent2->keyvalues["targetname"] == target) + auto targets = foundEnt->getTargets(); + Entity* targetEnt = NULL; + for (auto ent2 : map->ents) { - found = true; - break; + if (targetEnt) + break; + if (ent2->hasKey("targetname")) + { + for (auto target : targets) + { + if (ent2->keyvalues["targetname"] == target) + { + targetEnt = ent2; + break; + } + } + } + } + + if (targetEnt) + { + vec3 newAngle = targetEnt->origin - foundEnt->origin; + VectorAngles(newAngle, newAngle); + newAngle[0] = -newAngle[0]; + renderCameraAngles = newAngle; } } + + renderCameraAngles = renderCameraAngles.flip(); + renderCameraAngles.z = renderCameraAngles.z + 90.0f; + renderCameraAngles = renderCameraAngles.normalize_angles(); + renderCameraAngles.y = 0.0f; } } - */ - /* break; - } -}*/ - } if (g_settings.save_cam) diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index c1194bba..e3a4d970 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -552,25 +552,25 @@ void Renderer::renderLoop() GLuint fbo = NULL, texture, rbo; - if (ortho_overview) - { - if (ortho_save_tga || ortho_save_bmp) - { - setupFakeOrthoView(ortho_tga_w, ortho_tga_h, ortho_mins, ortho_maxs); - } - else - { - setupFakeOrthoView(0, 0, ortho_mins, ortho_maxs); - } - } - else + if (ortho_save_tga || ortho_save_bmp || (make_screenshot && !isLoading)) { - setupView(); - } + glEnable(GL_MULTISAMPLE); + glEnable(GL_LINE_SMOOTH); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + glEnable(GL_POLYGON_SMOOTH); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); + glEnable(GL_POINT_SMOOTH); + glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + + glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_NICEST); + + + //for (auto& tex : g_all_Textures) + //{ + // tex->upload(tex->type); + //} - if (ortho_save_tga || ortho_save_bmp || (make_screenshot && !isLoading)) - { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -598,9 +598,12 @@ void Renderer::renderLoop() Bsp* map = SelectedMap; if (map) { - int tries = make_screenshot_target; + int tries = make_screenshot_target + 1; BspRenderer* rend = SelectedMap->getBspRender(); Entity* foundEnt = NULL; + + bool foundCam = false; + for (auto ent : map->ents) { if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera") @@ -608,6 +611,7 @@ void Renderer::renderLoop() tries--; if (tries <= 0) { + foundCam = true; foundEnt = ent; break; } @@ -662,34 +666,66 @@ void Renderer::renderLoop() if (foundEnt) { rend->renderCameraOrigin = foundEnt->origin; - rend->renderCameraOrigin.z += 32; - for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++) + if (!foundCam) { - if (foundEnt->keyOrder[i] == "angles") - { - rend->renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]); - } - if (foundEnt->keyOrder[i] == "angle") + rend->renderCameraOrigin.z += 32; + for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++) { - float y = str_to_float(foundEnt->keyvalues["angle"]); - - if (y >= 0.0f) + if (foundEnt->keyOrder[i] == "angles") { - rend->renderCameraAngles.y = y; + rend->renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]); } - else if (y == -1.0f) + if (foundEnt->keyOrder[i] == "angle") { - rend->renderCameraAngles.x = -90.0f; - rend->renderCameraAngles.y = 0.0f; - rend->renderCameraAngles.z = 0.0f; + float y = str_to_float(foundEnt->keyvalues["angle"]); + + if (y >= 0.0f) + { + rend->renderCameraAngles.y = y; + } + else if (y == -1.0f) + { + rend->renderCameraAngles.x = -90.0f; + rend->renderCameraAngles.y = 0.0f; + rend->renderCameraAngles.z = 0.0f; + } + else if (y <= -2.0f) + { + rend->renderCameraAngles.x = 90.0f; + rend->renderCameraAngles.y = 0.0f; + rend->renderCameraAngles.z = 0.0f; + } } - else if (y <= -2.0f) + } + } + else + { + auto targets = foundEnt->getTargets(); + Entity* targetEnt = NULL; + for (auto ent2 : map->ents) + { + if (targetEnt) + break; + if (ent2->hasKey("targetname")) { - rend->renderCameraAngles.x = 90.0f; - rend->renderCameraAngles.y = 0.0f; - rend->renderCameraAngles.z = 0.0f; + for (auto target : targets) + { + if (ent2->keyvalues["targetname"] == target) + { + targetEnt = ent2; + break; + } + } } } + + if (targetEnt) + { + vec3 newAngle = targetEnt->origin - foundEnt->origin; + VectorAngles(newAngle, newAngle); + newAngle[0] = -newAngle[0]; + rend->renderCameraAngles = newAngle; + } } rend->renderCameraAngles = rend->renderCameraAngles.flip(); @@ -705,6 +741,32 @@ void Renderer::renderLoop() } } + + + if (ortho_overview) + { + if (ortho_save_tga || ortho_save_bmp) + { + setupFakeOrthoView(ortho_tga_w, ortho_tga_h, ortho_mins, ortho_maxs); + } + else + { + setupFakeOrthoView(0, 0, ortho_mins, ortho_maxs); + } + } + else + { + if (make_screenshot) + { + setupView(ortho_tga_w, ortho_tga_h); + } + else + { + setupView(); + } + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Update keyboard / mouse state @@ -1291,12 +1353,8 @@ void Renderer::renderLoop() if (ortho_save_tga || (make_screenshot && !isLoading)) { - make_screenshot--; - make_screenshot_target++; - if (make_screenshot) { - std::string screenPath = g_working_dir; @@ -1317,6 +1375,10 @@ void Renderer::renderLoop() print_log("Saved to {} file!\n", (g_working_dir + "overview.tga")); } + make_screenshot--; + make_screenshot_target++; + + if (make_screenshot <= 0) { is_closing = true; diff --git a/src/gl/Texture.cpp b/src/gl/Texture.cpp index f33f4baa..028774aa 100644 --- a/src/gl/Texture.cpp +++ b/src/gl/Texture.cpp @@ -129,6 +129,18 @@ void Texture::upload(int _type) break; } + if (make_screenshot) + { + if (GLEW_EXT_texture_filter_anisotropic) + { + GLfloat maxAniso = 0.0f; + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast(maxAniso)); + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + if (texName[0] == '{' && format == GL_RGB) { format = GL_RGBA; @@ -151,7 +163,7 @@ void Texture::upload(int _type) glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); - + //glGenerateMipmap(GL_TEXTURE_2D); if (g_settings.verboseLogs) print_log(get_localized_string(LANG_0971), texName, width, height); diff --git a/src/util/vectors.cpp b/src/util/vectors.cpp index 8a891e22..cd98f994 100644 --- a/src/util/vectors.cpp +++ b/src/util/vectors.cpp @@ -950,4 +950,33 @@ float clamp(float val, float min, float max) return min; } return val; +} + +void VectorAngles(const vec3 & forward, vec3 & angles) +{ + float tmp, yaw, pitch; + + if (forward[1] == 0 && forward[0] == 0) + { + yaw = 0; + if (forward[2] > 0) + pitch = 90; + else + pitch = 270; + } + else + { + yaw = (atan2(forward[1], forward[0]) * 180 / Q_PI); + if (yaw < 0) + yaw += 360; + + tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]); + pitch = (atan2(forward[2], tmp) * 180 / Q_PI); + if (pitch < 0) + pitch += 360; + } + + angles[0] = pitch; + angles[1] = yaw; + angles[2] = 0; } \ No newline at end of file diff --git a/src/util/vectors.h b/src/util/vectors.h index 54e60c9e..124f82f8 100644 --- a/src/util/vectors.h +++ b/src/util/vectors.h @@ -430,3 +430,4 @@ void R_ConcatTransforms(float in1[][4], float in2[][4], float out[][4]); void VectorScale(const vec3& v, float scale, vec3& out); float VectorNormalize(vec3& v); float fullnormalizeangle(float angle); +void VectorAngles(const vec3& forward, vec3& angles); \ No newline at end of file diff --git a/vs-project/bspguy.vcxproj.user b/vs-project/bspguy.vcxproj.user index 1a12d203..1ebab7e1 100644 --- a/vs-project/bspguy.vcxproj.user +++ b/vs-project/bspguy.vcxproj.user @@ -19,7 +19,7 @@ WindowsLocalDebugger - screenshot D:\SteamLibrary\steamapps\common\Half-Life\cstrike\maps\de_dust2.bsp -count 5 -w 1200 -h 800 + D:\SteamLibrary\steamapps\common\Half-Life\cstrike\maps\de_dust2.bsp WindowsLocalDebugger .\..\vs-project\Release\