Merge pull request #304 from MohamedWaheed/dev
Savefile screenshot implementation and screenshot loading bug fixdev-mp
commit
ae13e0a621
|
@ -78,16 +78,22 @@ std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath)
|
||||||
|
|
||||||
for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
|
for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
str << *rit;
|
|
||||||
str << "/";
|
if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot
|
||||||
str << m_standardDataDirs[index];
|
str << *rit;
|
||||||
if (dir == DIR_HELP)
|
str << "/";
|
||||||
{
|
str << m_standardDataDirs[index];
|
||||||
|
|
||||||
|
if (dir == DIR_HELP)
|
||||||
|
{
|
||||||
|
str << "/";
|
||||||
|
str << CApplication::GetInstancePointer()->GetLanguageChar();
|
||||||
|
}
|
||||||
str << "/";
|
str << "/";
|
||||||
str << CApplication::GetInstancePointer()->GetLanguageChar();
|
|
||||||
}
|
}
|
||||||
str << "/";
|
|
||||||
str << subpath;
|
str << subpath;
|
||||||
|
|
||||||
boost::filesystem::path path(str.str());
|
boost::filesystem::path path(str.str());
|
||||||
if(boost::filesystem::exists(path))
|
if(boost::filesystem::exists(path))
|
||||||
{
|
{
|
||||||
|
@ -95,18 +101,9 @@ std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream str;
|
GetLogger()->Error("file subpath error\n");
|
||||||
str << m_dataDirs[0];
|
|
||||||
str << "/";
|
return "";
|
||||||
str << m_standardDataDirs[index];
|
|
||||||
if (dir == DIR_HELP)
|
|
||||||
{
|
|
||||||
str << "/";
|
|
||||||
str << CApplication::GetInstancePointer()->GetLanguageChar();
|
|
||||||
}
|
|
||||||
str << "/";
|
|
||||||
str << subpath;
|
|
||||||
return str.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CGameData::GetDataPath(const std::string &subpath)
|
std::string CGameData::GetDataPath(const std::string &subpath)
|
||||||
|
|
|
@ -418,3 +418,44 @@ bool CImage::SavePNG(const std::string& fileName)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CImage::SetDataPixels(void *pixels){
|
||||||
|
|
||||||
|
Uint8* srcPixels = static_cast<Uint8*> (pixels);
|
||||||
|
Uint8* resultPixels = static_cast<Uint8*> (m_data->surface->pixels);
|
||||||
|
|
||||||
|
Uint32 pitch = m_data->surface->pitch;
|
||||||
|
|
||||||
|
for(int line = 0; line < m_data->surface->h; ++line) {
|
||||||
|
Uint32 pos = line * pitch;
|
||||||
|
memcpy(&resultPixels[pos], &srcPixels[pos], pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CImage::flipVertically(){
|
||||||
|
|
||||||
|
SDL_Surface* result = SDL_CreateRGBSurface( m_data->surface->flags,
|
||||||
|
m_data->surface->w,
|
||||||
|
m_data->surface->h,
|
||||||
|
m_data->surface->format->BytesPerPixel * 8,
|
||||||
|
m_data->surface->format->Rmask,
|
||||||
|
m_data->surface->format->Gmask,
|
||||||
|
m_data->surface->format->Bmask,
|
||||||
|
m_data->surface->format->Amask);
|
||||||
|
|
||||||
|
assert(result != nullptr);
|
||||||
|
|
||||||
|
Uint8* srcPixels = static_cast<Uint8*> (m_data->surface->pixels);
|
||||||
|
Uint8* resultPixels = static_cast<Uint8*> (result->pixels);
|
||||||
|
|
||||||
|
Uint32 pitch = m_data->surface->pitch;
|
||||||
|
Uint32 pxLength = pitch*m_data->surface->h;
|
||||||
|
|
||||||
|
for(int line = 0; line < m_data->surface->h; ++line) {
|
||||||
|
Uint32 pos = line * pitch;
|
||||||
|
memcpy(&resultPixels[pos], &srcPixels[(pxLength-pos)-pitch], pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_FreeSurface(m_data->surface);
|
||||||
|
|
||||||
|
m_data->surface = result;
|
||||||
|
}
|
|
@ -109,6 +109,12 @@ public:
|
||||||
//! Returns the last error
|
//! Returns the last error
|
||||||
std::string GetError();
|
std::string GetError();
|
||||||
|
|
||||||
|
//! Flips the image vertically
|
||||||
|
void flipVertically();
|
||||||
|
|
||||||
|
//! sets/replaces the pixels from the surface
|
||||||
|
void SetDataPixels(void *pixels);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Blit to new RGBA surface with given size
|
//! Blit to new RGBA surface with given size
|
||||||
void BlitToNewRGBASurface(int width, int height);
|
void BlitToNewRGBASurface(int width, int height);
|
||||||
|
|
|
@ -400,6 +400,9 @@ public:
|
||||||
virtual void SetFillMode(FillMode mode) = 0;
|
virtual void SetFillMode(FillMode mode) = 0;
|
||||||
//! Returns the current fill mode
|
//! Returns the current fill mode
|
||||||
virtual FillMode GetFillMode() = 0;
|
virtual FillMode GetFillMode() = 0;
|
||||||
|
|
||||||
|
//! Returns the pixels of the entire screen
|
||||||
|
virtual void* GetFrameBufferPixels()const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -424,9 +424,20 @@ void CEngine::FrameUpdate()
|
||||||
|
|
||||||
bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height)
|
bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height)
|
||||||
{
|
{
|
||||||
// TODO write screenshot: not very important for now
|
void *pixels = m_device->GetFrameBufferPixels();
|
||||||
GetLogger()->Debug("CEngine::WriteSceenShot(): stub!\n");
|
CImage img({width,height});
|
||||||
return true;
|
|
||||||
|
img.SetDataPixels(pixels);
|
||||||
|
img.flipVertically();
|
||||||
|
|
||||||
|
if ( img.SavePNG(fileName.c_str()) ){
|
||||||
|
GetLogger()->Info("Save SceenShot Saved Successfully!\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
GetLogger()->Error("%s!\n",img.GetError().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CEngine::GetPause()
|
bool CEngine::GetPause()
|
||||||
|
|
|
@ -1791,6 +1791,19 @@ FillMode CGLDevice::GetFillMode()
|
||||||
return FILL_POINT;
|
return FILL_POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* CGLDevice::GetFrameBufferPixels()const{
|
||||||
|
|
||||||
|
GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y];
|
||||||
|
|
||||||
|
glReadPixels(0, 0, m_config.size.x, m_config.size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
|
unsigned int* p = static_cast<unsigned int*> ( static_cast<void*>(pixels) );
|
||||||
|
|
||||||
|
for (int i = 0; i < m_config.size.x * m_config.size.y; ++i)
|
||||||
|
p[i] |= 0xFF000000;
|
||||||
|
|
||||||
|
return static_cast<void*>(p);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Gfx
|
} // namespace Gfx
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,8 @@ public:
|
||||||
virtual void SetFillMode(FillMode mode) ;
|
virtual void SetFillMode(FillMode mode) ;
|
||||||
virtual FillMode GetFillMode();
|
virtual FillMode GetFillMode();
|
||||||
|
|
||||||
|
virtual void* GetFrameBufferPixels()const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Updates internal modelview matrix
|
//! Updates internal modelview matrix
|
||||||
void UpdateModelviewMatrix();
|
void UpdateModelviewMatrix();
|
||||||
|
|
|
@ -2076,8 +2076,9 @@ bool CMainDialog::EventProcess(const Event &event)
|
||||||
m_shotDelay --;
|
m_shotDelay --;
|
||||||
if ( m_shotDelay == 0 )
|
if ( m_shotDelay == 0 )
|
||||||
{
|
{
|
||||||
m_engine->WriteScreenShot(m_shotName, 320, 240);
|
Math::IntPoint windowSize = m_engine->GetWindowSize();
|
||||||
//? m_engine->WriteScreenShot(m_shotName, 160, 120);
|
|
||||||
|
m_engine->WriteScreenShot(m_shotName, windowSize.x, windowSize.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue