Skip to content

Commit

Permalink
SurveyMap now zooms to static texture
Browse files Browse the repository at this point in the history
There are issues though:
* Even after hardcoding the texture size to 4096x4096 (the maximum value guaranteed to be portable), the resolution doesn't look spectacular on the zoomed in map, even on small terrain like Auriga.
* On both DirectX9 and GL, I'm getting a strange fade-to-black effect where the texture renders all black until zoomed in. Even when inputting exactly uv0=(0,0) and uv1=(1,1) which is the same as imgui defaults, it renders black. When left without the arguments, it renders OK. I need to look closer at this.
  • Loading branch information
ohlidalp committed Oct 2, 2023
1 parent 91f99be commit 09d90ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
27 changes: 9 additions & 18 deletions source/main/gui/panels/GUI_SurveyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ void SurveyMap::Draw()

// Draw map texture
ImVec2 tl_screen_pos = ImGui::GetCursorScreenPos();
Ogre::TexturePtr tex;
Ogre::Vector2 smallmap_center;
Ogre::Vector2 smallmap_size;
Ogre::Vector2 view_origin;
Ogre::Vector2 texcoords_top_left(0,0);
Ogre::Vector2 texcoords_bottom_right(1,1);
if (mMapMode == SurveyMapMode::BIG)
{
tex = mMapTextureCreatorStatic->GetTexture();
view_origin = mMapCenterOffset;
}
else if (mMapMode == SurveyMapMode::SMALL)
Expand All @@ -155,12 +155,8 @@ void SurveyMap::Draw()

view_origin = ((smallmap_center + mMapCenterOffset) - smallmap_size / 2);

// Update texture
if (mMapZoom != 0.0f)
{
mMapTextureCreatorDynamic->update(smallmap_center + mMapCenterOffset, smallmap_size);
}
tex = mMapTextureCreatorDynamic->GetTexture();
texcoords_top_left = (smallmap_center - (smallmap_size/2)) / mTerrainSize;
texcoords_bottom_right = (smallmap_center + (smallmap_size/2)) / mTerrainSize;
}

bool w_adj = false;
Expand All @@ -175,10 +171,12 @@ void SurveyMap::Draw()
}
}
}

ImGui::Text("DBG uv0=%5.3f %5.3f, uv1=%5.3f %5.3f", texcoords_top_left.x, texcoords_top_left.y, texcoords_bottom_right.x, texcoords_bottom_right.y);
ImGui::BeginChild("map", ImVec2(0.f, view_size.y), false);
ImGui::Image(reinterpret_cast<ImTextureID>(mMapTextureCreatorStatic->GetTexture()->getHandle()), view_size,
ImVec2(texcoords_top_left.x, texcoords_top_left.y),
ImVec2(texcoords_bottom_right.x, texcoords_bottom_right.y));

ImGui::Image(reinterpret_cast<ImTextureID>(tex->getHandle()), view_size);
if (ImGui::IsItemClicked(0) || ImGui::IsItemClicked(1)) // 0 = left click, 1 = right click
{
ImVec2 mouse_view_offset = (ImGui::GetMousePos() - tl_screen_pos) / view_size;
Expand Down Expand Up @@ -393,18 +391,11 @@ void SurveyMap::CreateTerrainTextures()
Ogre::Vector2 mMapCenter = mTerrainSize / 2;

ConfigOptionMap ropts = App::GetAppContext()->GetOgreRoot()->getRenderSystem()->getConfigOptions();
int resolution = StringConverter::parseInt(StringUtil::split(ropts["Video Mode"].currentValue, " x ")[0], 1024);
int fsaa = StringConverter::parseInt(ropts["FSAA"].currentValue, 0);
int res = std::pow(2, std::floor(std::log2(resolution)));

mMapTextureCreatorStatic = std::unique_ptr<SurveyMapTextureCreator>(new SurveyMapTextureCreator(terrain_size.y));
mMapTextureCreatorStatic->init(res / 1.5, fsaa);
mMapTextureCreatorStatic->init(4096, fsaa);
mMapTextureCreatorStatic->update(mMapCenter + mMapCenterOffset, mTerrainSize);

// TODO: Find out how to zoom into the static texture instead
mMapTextureCreatorDynamic = std::unique_ptr<SurveyMapTextureCreator>(new SurveyMapTextureCreator(terrain_size.y));
mMapTextureCreatorDynamic->init(res / 4, fsaa);
mMapTextureCreatorDynamic->update(mMapCenter + mMapCenterOffset, mTerrainSize);
}


Expand Down
1 change: 0 additions & 1 deletion source/main/gui/panels/GUI_SurveyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class SurveyMap
float mMapZoom = 0.f; // Ratio: 0-1

std::unique_ptr<SurveyMapTextureCreator> mMapTextureCreatorStatic;
std::unique_ptr<SurveyMapTextureCreator> mMapTextureCreatorDynamic;

// Icon cache
bool m_icons_cached = false;
Expand Down

0 comments on commit 09d90ab

Please sign in to comment.