summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-30 00:23:26 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-30 00:23:26 +0200
commitb46dc3850f489dca68fabe4512a611aed32e7df5 (patch)
treea0b8c0f35c270ca7a207f2d3788d8c73cbf47707 /src/ui
parenta8554cfae3358af6b909c45ba9dc9bdfc020bdfb (diff)
downloadcolobot-b46dc3850f489dca68fabe4512a611aed32e7df5.tar.gz
colobot-b46dc3850f489dca68fabe4512a611aed32e7df5.tar.bz2
colobot-b46dc3850f489dca68fabe4512a611aed32e7df5.zip
Map texture painting
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/map.cpp57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/ui/map.cpp b/src/ui/map.cpp
index 43d9b7b..06d570f 100644
--- a/src/ui/map.cpp
+++ b/src/ui/map.cpp
@@ -20,6 +20,8 @@
#include "ui/map.h"
+#include "common/image.h"
+
#include <string.h>
@@ -986,63 +988,60 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom)
void CMap::UpdateTerrain()
{
- Gfx::Color color;
- Math::Vector pos;
- float scale, water, level, intensity;
- int x, y;
-
- if ( m_fixImage[0] != 0 ) return; // still image?
+ if (m_fixImage[0] != 0) return; // still image?
- // TODO: map texture manipulation
- return;
+ CImage img(Math::IntPoint(256, 256));
- // if ( !m_engine->OpenImage("map.png") ) return;
+ float scale = m_terrain->GetReliefScale();
+ float water = m_water->GetLevel();
- scale = m_terrain->GetReliefScale();
- water = m_water->GetLevel();
+ Gfx::Color color;
color.a = 0.0f;
- for ( y=0 ; y<256 ; y++ )
+ for (int y = 0; y < 256; y++)
{
- for ( x=0 ; x<256 ; x++ )
+ for (int x = 0; x < 256; x++)
{
- pos.x = (static_cast<float>(x)-128.0f)*m_half/128.0f;
- pos.z = -(static_cast<float>(y)-128.0f)*m_half/128.0f;
+ Math::Vector pos;
+ pos.x = (static_cast<float>(x) - 128.0f) * m_half / 128.0f;
+ pos.z = -(static_cast<float>(y) - 128.0f) * m_half / 128.0f;
pos.y = 0.0f;
+ float level;
+
if ( pos.x >= -m_half && pos.x <= m_half &&
pos.z >= -m_half && pos.z <= m_half )
{
- level = m_terrain->GetFloorLevel(pos, true)/scale;
+ level = m_terrain->GetFloorLevel(pos, true) / scale;
}
else
{
level = 1000.0f;
}
- intensity = level/256.0f;
- if ( intensity < 0.0f ) intensity = 0.0f;
- if ( intensity > 1.0f ) intensity = 1.0f;
+ float intensity = level / 256.0f;
+ if (intensity < 0.0f) intensity = 0.0f;
+ if (intensity > 1.0f) intensity = 1.0f;
- if ( level >= water ) // on water?
+ if (level >= water) // on water?
{
- color.r = m_floorColor.r + (intensity-0.5f);
- color.g = m_floorColor.g + (intensity-0.5f);
- color.b = m_floorColor.b + (intensity-0.5f);
+ color.r = Math::Norm(m_floorColor.r + (intensity - 0.5f));
+ color.g = Math::Norm(m_floorColor.g + (intensity - 0.5f));
+ color.b = Math::Norm(m_floorColor.b + (intensity - 0.5f));
}
else // underwater?
{
- color.r = m_waterColor.r + (intensity-0.5f);
- color.g = m_waterColor.g + (intensity-0.5f);
- color.b = m_waterColor.b + (intensity-0.5f);
+ color.r = Math::Norm(m_waterColor.r + (intensity - 0.5f));
+ color.g = Math::Norm(m_waterColor.g + (intensity - 0.5f));
+ color.b = Math::Norm(m_waterColor.b + (intensity - 0.5f));
}
- //m_engine->SetDot(x, y, color);
+ img.SetPixel(Math::IntPoint(x, y), color);
}
}
- //m_engine->CopyImage(); // copy the ground drawing
- //m_engine->CloseImage();
+ m_engine->DeleteTexture("map.png");
+ m_engine->LoadTexture("map.png", &img);
}
// Updates the field in the map.