From 613e1d74c47cf3a756af9aff75575c7567699381 Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 01:35:05 +0300 Subject: implemented savefile screenshot feature --- src/graphics/core/device.h | 3 +++ src/graphics/engine/engine.cpp | 17 ++++++++++++++--- src/graphics/opengl/gldevice.cpp | 17 +++++++++++++++++ src/graphics/opengl/gldevice.h | 2 ++ 4 files changed, 36 insertions(+), 3 deletions(-) (limited to 'src/graphics') diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 4c1189c..a896104 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -400,6 +400,9 @@ public: virtual void SetFillMode(FillMode mode) = 0; //! Returns the current fill mode virtual FillMode GetFillMode() = 0; + + //! Returns the pixels of the entire screen + virtual void* GetFrameBufferPixels()const = 0; }; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index d6e4415..9216fb0 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -424,9 +424,20 @@ void CEngine::FrameUpdate() bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height) { - // TODO write screenshot: not very important for now - GetLogger()->Debug("CEngine::WriteSceenShot(): stub!\n"); - return true; + void *pixels = m_device->GetFrameBufferPixels(); + CImage img({width,height}); + + img.SetDataPixels(pixels); + img.flipVertical(); + + 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() diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 9f64fab..57738a6 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1791,6 +1791,23 @@ FillMode CGLDevice::GetFillMode() return FILL_POINT; } +void* CGLDevice::GetFrameBufferPixels()const{ + + SDL_Surface* surface = SDL_GetVideoSurface(); + + assert(surface != nullptr); + + GLubyte* pixels = new GLubyte [4 * surface->h * surface->w]; + + glReadPixels(0,0,surface->w,surface->h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); + + unsigned int* p = static_cast ( static_cast(pixels) ); + + for (int i = 0; i < surface->h * surface->w; ++i) + p[i] |= 0xFF000000; + + return static_cast(p); +} } // namespace Gfx diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index c648161..267ee73 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -188,6 +188,8 @@ public: virtual void SetFillMode(FillMode mode) ; virtual FillMode GetFillMode(); + virtual void* GetFrameBufferPixels()const; + private: //! Updates internal modelview matrix void UpdateModelviewMatrix(); -- cgit v1.2.3-1-g7c22 From b7125a5b24bc6d2581bec0d3f792ba948e0e7edd Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 20:27:31 +0300 Subject: formatting and enhancements for savefile screenshot feature --- src/graphics/engine/engine.cpp | 2 +- src/graphics/opengl/gldevice.cpp | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'src/graphics') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 9216fb0..e0861d2 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -428,7 +428,7 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height CImage img({width,height}); img.SetDataPixels(pixels); - img.flipVertical(); + img.flipVertically(); if ( img.SavePNG(fileName.c_str()) ){ GetLogger()->Info("Save SceenShot Saved Successfully!\n"); diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 57738a6..b42f29d 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1793,17 +1793,13 @@ FillMode CGLDevice::GetFillMode() void* CGLDevice::GetFrameBufferPixels()const{ - SDL_Surface* surface = SDL_GetVideoSurface(); - - assert(surface != nullptr); - - GLubyte* pixels = new GLubyte [4 * surface->h * surface->w]; + GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y]; - glReadPixels(0,0,surface->w,surface->h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); + glReadPixels(0, 0, m_config.size.x, m_config.size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); unsigned int* p = static_cast ( static_cast(pixels) ); - for (int i = 0; i < surface->h * surface->w; ++i) + for (int i = 0; i < m_config.size.x * m_config.size.y; ++i) p[i] |= 0xFF000000; return static_cast(p); -- cgit v1.2.3-1-g7c22 From 0fbc05b96ca9b464b273d64349d9a7940a0c992b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 26 Jun 2014 22:36:57 +0200 Subject: Fix test compilation --- src/graphics/core/vertex.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/graphics') diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index c3a657a..ca68352 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -82,7 +82,9 @@ struct VertexCol Math::Vector coord; Color color; - explicit VertexCol(Math::Vector aCoord = Math::Vector(), + VertexCol() = default; + + explicit VertexCol(Math::Vector aCoord, Color aColor = Color()) : coord(aCoord), color(aColor) {} -- cgit v1.2.3-1-g7c22 From 1835d2ae580525603308206f7b8e6b4552b3ca0f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Jun 2014 19:50:09 +0200 Subject: Removed old code based on #ifs (issue #55) --- src/graphics/engine/camera.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/graphics') diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index f0c379c..fedc70a 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -593,9 +593,6 @@ void CCamera::EffectFrame(const Event &event) dist = Math::Norm((dist - 100.f) / 100.0f); force *= 1.0f-dist; -#if _TEEN - force *= 2.0f; -#endif m_effectOffset *= force; if (m_effectProgress >= 1.0f) -- cgit v1.2.3-1-g7c22