Map texture painting
parent
a8554cfae3
commit
b46dc3850f
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)))
|
||||
{
|
||||
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;
|
||||
|
||||
Texture tex = m_device->CreateTexture(&img, params);
|
||||
if (image == nullptr)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
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())
|
||||
|
|
|
@ -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 ¶ms);
|
||||
Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr);
|
||||
|
||||
//! Tests whether the given object is visible
|
||||
bool IsVisible(int objRank);
|
||||
|
|
|
@ -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?
|
||||
CImage img(Math::IntPoint(256, 256));
|
||||
|
||||
// TODO: map texture manipulation
|
||||
return;
|
||||
float scale = m_terrain->GetReliefScale();
|
||||
float water = m_water->GetLevel();
|
||||
|
||||
// if ( !m_engine->OpenImage("map.png") ) return;
|
||||
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue