diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp index f88e47f..68d78e7 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp @@ -7,11 +7,11 @@ using VideoEngine::cImage; using UtilityEngine::cUtility; -cImage::cImage( const cString& dir /*= ""*/, const cString& filename /*= ""*/, const bool transparent /*= false*/, +cImage::cImage( const cString& filename, const cString& dir /*= ""*/, const bool transparent /*= false*/, const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/, - const unsigned char translevel /*= 255*/) -: mp_texture(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent), -m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel) + const unsigned char translevel /*= 255*/, const bool isSurface /*= false*/ ) +: mp_texture(nullptr), mp_surface(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent), +m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel), m_isSurface(isSurface) { if (m_fileName != (char*)"") LoadImage(); @@ -20,21 +20,21 @@ m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel } cImage::cImage( SDL_Surface* surface ) -: mp_texture(nullptr), m_dir(""), m_fileName(""), m_transparent(false), +: mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false), m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255) { setImage(surface); } cImage::cImage( SDL_Texture* texture ) - : mp_texture(nullptr), m_dir(""), m_fileName(""), m_transparent(false), + : mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false), m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255) { setImage(texture); } cImage::cImage( const cImage& copy, const bool surfaceCopy /*= true*/) -: mp_texture(nullptr), m_dir(copy.getDir()), +: mp_texture(nullptr), mp_surface(nullptr), m_dir(copy.getDir()), m_fileName(copy.getFileName()), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()), m_transBlue(copy.getBlueTrans()), m_transGreen(copy.getGreenTrans()), m_transLevel(copy.getLevelTrans()) { @@ -50,7 +50,10 @@ cImage::~cImage() ///Functions void cImage::SaveImage( const cString& fileName, const cString& dir /*= ""*/ ) { - cRenderer::Inst().SaveTexture( mp_texture, fileName, dir ); + if (m_isSurface == false) + cRenderer::Inst().SaveTexture(mp_texture, fileName, dir); + else + cRenderer::Inst().SaveSurface(mp_surface, fileName, dir); } const cImage* cImage::NewImage( SDL_Rect& area ) const @@ -114,7 +117,8 @@ void cImage::setLevelTrans( const unsigned char translevel /*= 255*/ ) ///Gets SDL_Surface* cImage::getSurface() const { - return cRenderer::Inst().TextureToSurface(mp_texture); + return mp_surface; + //return cRenderer::Inst().TextureToSurface(mp_texture); } SDL_Texture* cImage::getImage() const @@ -203,6 +207,11 @@ const unsigned char cImage::getLevelTrans() const return m_transLevel; } +const bool cImage::getIsSurface() const +{ + return m_isSurface; +} + //protected: void cImage::setImage( SDL_Surface* surface ) { @@ -235,13 +244,24 @@ void cImage::LoadImage() UnloadImage(); SDL_Texture* tempText = nullptr; + SDL_Surface* tempSurface = nullptr; if (m_fileName != "") { cString temp = m_dir + m_fileName; - if ((tempText = IMG_LoadTexture( cRenderer::Inst().getRenderer(), temp.c_str() )) == nullptr) - cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE); + if (m_isSurface == false) { + if ((tempText = IMG_LoadTexture(cRenderer::Inst().getRenderer(), temp.c_str())) == nullptr) + cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE); + else + mp_texture = tempText; + } + else { + if ((tempSurface = IMG_Load(temp.c_str())) == nullptr) + cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_Load():", __AT__, cUtility::eTypeSDL::IMAGE); + else + mp_surface = tempSurface; + } } } diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp index 837060c..b4fadbe 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp @@ -17,9 +17,9 @@ namespace VideoEngine { class EXPORT_FROM_MYDLL cImage { public: - cImage( const cString& dir = "", const cString& filename = "", const bool transparent = false, + cImage( const cString& filename = "", const cString& dir = "", const bool transparent = false, const unsigned char red = 0, const unsigned char blue = 0, const unsigned char green = 255, - const unsigned char translevel = 255); + const unsigned char translevel = 255, const bool isSurface = false ); cImage( SDL_Surface* surface ); cImage( SDL_Texture* texture ); /* Copy constructor */ @@ -78,6 +78,8 @@ namespace VideoEngine { /* Gets the transparent level 255 = clear, 0 = solid */ const unsigned char getLevelTrans() const; + const bool getIsSurface() const; + protected: /* Protected so only derived class can access. *. /* Sets the image to surface */ @@ -93,6 +95,7 @@ namespace VideoEngine { private: ///Variables SDL_Texture* mp_texture;// = nullptr + SDL_Surface* mp_surface;// = nullptr cString m_dir;// = "" cString m_fileName;// = "" @@ -106,7 +109,9 @@ namespace VideoEngine { unsigned char m_transBlue;// = 0 unsigned char m_transGreen;// = 255 - unsigned char m_transLevel;// = 255 + unsigned char m_transLevel;// = 255 + + bool m_isSurface; };/// END CLASS DEFINITION cImage }/// END NAMESPACE DEFINITION VideoEngine #endif/// END IFNDEF _CIMAGE_HPP_ diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp index f979fb6..58f667c 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp @@ -112,16 +112,9 @@ void cRenderer::RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst /*= nullp void cRenderer::ScreenShot( const cString& filename, const cString& dir /*= ""*/ ) { SDL_Surface* infoSurface = SDL_GetWindowSurface(VideoEngine::cVideo::Inst().getWindow()); - if (infoSurface == nullptr) - cUtility::Inst().Message("Failed to create info surface from window.\n", __AT__, cUtility::eTypeSDL::SDL); - else { - SaveSurface(infoSurface, filename, dir); - SDL_FreeSurface(infoSurface); - infoSurface = NULL; - } - /*SDL_Surface* saveSurface = NewSurface(); + SDL_Surface* saveSurface = NewSurface(); - if (infoSurface == NULL) { + if (infoSurface == nullptr) { cUtility::Inst().Message("Failed to create info surface from window.\n", __AT__, cUtility::eTypeSDL::SDL); } else { if (SDL_RenderReadPixels(mp_renderer, &infoSurface->clip_rect, infoSurface->format->format, saveSurface->pixels, infoSurface->w * infoSurface->format->BytesPerPixel) != 0) @@ -129,10 +122,10 @@ void cRenderer::ScreenShot( const cString& filename, const cString& dir /*= ""*/ else SaveSurface(saveSurface, filename, dir); SDL_FreeSurface(infoSurface); - infoSurface = NULL; + infoSurface = nullptr; } SDL_FreeSurface(saveSurface); - saveSurface = NULL;*/ + saveSurface = nullptr; } @@ -157,8 +150,7 @@ void cRenderer::SaveTexture( SDL_Texture* texture, const cString& fileName, cons SDL_Texture* cRenderer::SurfaceToTexture( SDL_Surface* surface ) { - SDL_Texture* rtn = nullptr; - rtn = SDL_CreateTextureFromSurface( mp_renderer, surface ); + SDL_Texture* rtn = SDL_CreateTextureFromSurface( mp_renderer, surface ); if ( rtn == nullptr) cUtility::Inst().Message("Unable to create Texture. SDL_CreateTextureFromSurface():", __AT__, cUtility::eTypeSDL::SDL); @@ -242,7 +234,7 @@ SDL_Surface* cRenderer::NewSurface( long int width /*= -1*/, long int height /*= if (height < 0) height = cVideo::Inst().getHeight(); - SDL_Surface* rtn = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), width, height, cVideo::Inst().getColour(), cVideo::Inst().getRmask(), cVideo::Inst().getGmask(), cVideo::Inst().getBmask(), cVideo::Inst().getAmask()); + SDL_Surface* rtn = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), width, height, cVideo::Inst().getColourDepth(), cVideo::Inst().getRmask(), cVideo::Inst().getGmask(), cVideo::Inst().getBmask(), cVideo::Inst().getAmask()); if (rtn == nullptr) cUtility::Inst().Message("Unable to create surface. SDL_CreateRGBSurface():", __AT__, cUtility::eTypeSDL::SDL); diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cSprite.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cSprite.cpp index 5ed76bd..3d1b3ce 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cSprite.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cSprite.cpp @@ -76,15 +76,20 @@ cSprite::~cSprite() ///Functions void cSprite::Draw() { - SDL_Texture* texture = (*mpp_image)->getImage(); + //SDL_Texture* texture = (*mpp_image)->getImage(); if (mpp_camera != nullptr && *mpp_camera != nullptr) { CameraDraw(); //surface = (*mpp_camera)->getCameraView(); } - if (mpp_image != nullptr && *mpp_image != nullptr) - cRenderer::Inst().Render( texture, &m_imageArea, &m_position); + if (mpp_image != nullptr && *mpp_image != nullptr) { + if ((*mpp_image)->getIsSurface() == false) + cRenderer::Inst().Render((*mpp_image)->getImage(), &m_imageArea, &m_position); + else + cRenderer::Inst().Render((*mpp_image)->getSurface(), &m_imageArea, &m_position); + } + // cRenderer::Inst().Render((*mpp_image)->getImage(), &m_imageArea, &m_position); } void cSprite::CameraDraw() @@ -103,8 +108,12 @@ void cSprite::CameraDraw() void cSprite::DefaltDraw() { - if (mpp_image != nullptr && *mpp_image != nullptr) - cRenderer::Inst().Render( (*mpp_image)->getImage(), nullptr, nullptr); + if (mpp_image != nullptr && *mpp_image != nullptr) { + if ((*mpp_image)->getIsSurface() == false) + cRenderer::Inst().Render((*mpp_image)->getImage(), nullptr, nullptr); + else + cRenderer::Inst().Render((*mpp_image)->getSurface(), nullptr, nullptr); + } } void cSprite::AddPosX( const signed long int x ) diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp index e82916b..2349dfc 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp @@ -197,11 +197,21 @@ const unsigned long int cVideo::getHeight() const return m_height; } -const unsigned long int cVideo::getColour() const +const unsigned long int cVideo::getColourDepth() const { return m_colour; } +const unsigned long int cVideo::getPitch() const +{ + unsigned long int rtn = 0; + if (cVideo::getColourDepth() == 32) + rtn = 4; // 4 bytes per pixel + else + rtn = 3; + return rtn; +} + const cString cVideo::getCaption() const { cString rtn = ""; diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.hpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.hpp index cadbcf4..37db58e 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.hpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.hpp @@ -68,7 +68,9 @@ namespace VideoEngine { /* Gets the videos height resolution */ const unsigned long int getHeight() const; /* Gets the videos colour depth in bits */ - const unsigned long int getColour() const; + const unsigned long int getColourDepth() const; + /* Gets the videos pitch */ + const unsigned long int getPitch() const; /* Gets the caption displayed on the window */ const cString getCaption() const; diff --git a/TrooperEngineTest/ImageTest.bmp b/TrooperEngineTest/ImageTest.bmp new file mode 100644 index 0000000..5bcf273 Binary files /dev/null and b/TrooperEngineTest/ImageTest.bmp differ diff --git a/TrooperEngineTest/ImageTestSaved.bmp b/TrooperEngineTest/ImageTestSaved.bmp new file mode 100644 index 0000000..72e2893 Binary files /dev/null and b/TrooperEngineTest/ImageTestSaved.bmp differ diff --git a/TrooperEngineTest/TrooperEngineTest.vcxproj b/TrooperEngineTest/TrooperEngineTest.vcxproj index 9c77a22..132b67b 100644 --- a/TrooperEngineTest/TrooperEngineTest.vcxproj +++ b/TrooperEngineTest/TrooperEngineTest.vcxproj @@ -150,6 +150,7 @@ + @@ -158,6 +159,7 @@ + diff --git a/TrooperEngineTest/TrooperEngineTest.vcxproj.filters b/TrooperEngineTest/TrooperEngineTest.vcxproj.filters index 07b34e7..6212f76 100644 --- a/TrooperEngineTest/TrooperEngineTest.vcxproj.filters +++ b/TrooperEngineTest/TrooperEngineTest.vcxproj.filters @@ -39,6 +39,9 @@ VideoEngineTest + + VideoEngineTest + @@ -60,6 +63,9 @@ VideoEngineTest + + VideoEngineTest + diff --git a/TrooperEngineTest/VideoEngineTest/ImageTest.cpp b/TrooperEngineTest/VideoEngineTest/ImageTest.cpp new file mode 100644 index 0000000..1024cad --- /dev/null +++ b/TrooperEngineTest/VideoEngineTest/ImageTest.cpp @@ -0,0 +1,29 @@ +#include "ImageTest.hpp" + +#include "../UTest/UTest.hpp" + +/*** TrooperEngine DLL Header Files ***/ +#include "TrooperEngine.hpp" + +using VideoEngine::cImage; + +using VideoEngine::cSprite; + +void ImageTest() +{ + // cRenderer + printf("\nTesting cImage -----\n\n"); + + UTest u("cImage"); + + cImage* image = new cImage("ImageTest.bmp", "", false, 0, 0, 255, 255, true); + + image->SaveImage("ImageTestSaved.bmp"); + + cSprite* sprite = new cSprite(&image); + + sprite->Draw(); + + + u.report(); +} \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/ImageTest.hpp b/TrooperEngineTest/VideoEngineTest/ImageTest.hpp new file mode 100644 index 0000000..f7c1ec5 --- /dev/null +++ b/TrooperEngineTest/VideoEngineTest/ImageTest.hpp @@ -0,0 +1,6 @@ +#ifndef __IMAGETEST__ +#define __IMAGETEST__ + +void ImageTest(); + +#endif // __IMAGETEST__ diff --git a/TrooperEngineTest/main.cpp b/TrooperEngineTest/main.cpp index 05cdba1..6ddd5dd 100644 --- a/TrooperEngineTest/main.cpp +++ b/TrooperEngineTest/main.cpp @@ -23,6 +23,7 @@ see license.txt for details /*** Video Engine Test ***/ #include "VideoEngineTest/VideoTest.hpp" +#include "VideoEngineTest/ImageTest.hpp" /*** Utility Engine Test ***/ #include "UtilityEngineTest/StringTest.hpp" @@ -52,6 +53,8 @@ int main(int argc, char *argv[]) GUIXMLTest(); + ImageTest(); + UTest::OverAllReport(); SDL_Event event; diff --git a/TrooperEngineTest/xml/GUIXMLBoxSizerTest.xml b/TrooperEngineTest/xml/GUIXMLBoxSizerTest.xml index 7d41fdf..7446883 100644 --- a/TrooperEngineTest/xml/GUIXMLBoxSizerTest.xml +++ b/TrooperEngineTest/xml/GUIXMLBoxSizerTest.xml @@ -2,7 +2,7 @@ - \ No newline at end of file