summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common/image.cpp7
-rw-r--r--src/common/image.h2
-rw-r--r--src/graphics/engine/engine.cpp33
-rw-r--r--src/graphics/engine/engine.h6
-rw-r--r--src/ui/map.cpp57
5 files changed, 66 insertions, 39 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp
index 6a2ab0e..f78ea94 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -147,6 +147,13 @@ CImage::CImage()
m_data = nullptr;
}
+CImage::CImage(Math::IntPoint size)
+{
+ m_data = new ImageData();
+ m_data->surface = SDL_CreateRGBSurface(0, size.x, size.y, 32,
+ 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
+}
+
CImage::~CImage()
{
Free();
diff --git a/src/common/image.h b/src/common/image.h
index 3391bdb..54bbd3d 100644
--- a/src/common/image.h
+++ b/src/common/image.h
@@ -60,6 +60,8 @@ private:
public:
//! Constructs empty image (with NULL data)
CImage();
+ //! Constructs a RGBA image of given size
+ CImage(Math::IntPoint size);
//! Destroys image, calling Free()
virtual ~CImage();
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index b4ad962..7e00134 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -2074,7 +2074,7 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka
m_sound->SetListener(eyePt, lookatPt);
}
-Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params)
+Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image)
{
if (texName.empty())
return Texture(); // invalid texture
@@ -2082,16 +2082,25 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa
if (m_texBlacklist.find(texName) != m_texBlacklist.end())
return Texture(); // invalid texture
- CImage img;
- if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName)))
+ Texture tex;
+
+ if (image == nullptr)
{
- std::string error = img.GetError();
- GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
- m_texBlacklist.insert(texName);
- return Texture(); // invalid texture
- }
+ CImage img;
+ if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName)))
+ {
+ std::string error = img.GetError();
+ GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
+ m_texBlacklist.insert(texName);
+ return Texture(); // invalid texture
+ }
- Texture tex = m_device->CreateTexture(&img, params);
+ tex = m_device->CreateTexture(&img, params);
+ }
+ else
+ {
+ tex = m_device->CreateTexture(image, params);
+ }
if (! tex.Valid())
{
@@ -2111,6 +2120,12 @@ Texture CEngine::LoadTexture(const std::string& name)
return LoadTexture(name, m_defaultTexParams);
}
+Texture CEngine::LoadTexture(const std::string& name, CImage* image)
+{
+ Texture tex = CreateTexture(name, m_defaultTexParams, image);
+ return tex;
+}
+
Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& params)
{
if (m_texBlacklist.find(name) != m_texBlacklist.end())
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index cbe5d04..14a40db 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -48,6 +48,7 @@ class CApplication;
class CInstanceManager;
class CObject;
class CSoundInterface;
+class CImage;
// Graphics module namespace
@@ -891,11 +892,14 @@ public:
//! Loads texture, creating it if not already present
Texture LoadTexture(const std::string& name);
+ //! Loads texture from existing image
+ Texture LoadTexture(const std::string& name, CImage* image);
//! Loads texture, creating it with given params if not already present
Texture LoadTexture(const std::string& name, const TextureCreateParams& params);
//! Loads all necessary textures
bool LoadAllTextures();
+ //! Changes colors in a texture
bool ChangeTextureColor(const std::string& texName,
Color colorRef1, Color colorNew1,
Color colorRef2, Color colorNew2,
@@ -1196,7 +1200,7 @@ protected:
const Material& mat, int state);
//! Create texture and add it to cache
- Texture CreateTexture(const std::string &texName, const TextureCreateParams &params);
+ Texture CreateTexture(const std::string &texName, const TextureCreateParams &params, CImage* image = nullptr);
//! Tests whether the given object is visible
bool IsVisible(int objRank);
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.