diff --git a/include/olcPixelGameEngine.hpp b/include/olcPixelGameEngine.hpp index a35dc5b..cd227d8 100644 --- a/include/olcPixelGameEngine.hpp +++ b/include/olcPixelGameEngine.hpp @@ -2118,7 +2118,7 @@ namespace olc { fFrameTimer -= 1.0f; - std::string sTitle = "OneLoneCoder.com - Pixel Game Engine - " + sAppName + " - FPS: " + std::to_string( nFrameCount ); + std::string sTitle = sAppName + " - FPS: " + std::to_string( nFrameCount ); #if defined(_WIN32) #ifdef UNICODE SetWindowText( olc_hWnd, ConvertS2W( sTitle ).c_str() ); diff --git a/src/display.cpp b/src/display.cpp index 7ef7e76..d67e5ad 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -68,7 +68,41 @@ bool Aeon::Display::OnUserUpdate( float fElapsedTime ) if ( mNewFrame ) { - + + if ( mNextFrame == nullptr ) + { + mNewFrame = false; + return true; + } + + for ( int x = 0; x < mNextFrame->w; x++ ) + for ( int y = 0; y < mNextFrame->w; y++ ) + { + // tonemap, gamma correct and write + // colours are assumed to input as HDR + + auto Clamp = []( glm::vec3 p, float max, float min ) -> glm::vec3 + { + glm::vec3 ret; + ret.r = std::max( min, std::min( p.r, max ) ); + ret.g = std::max( min, std::min( p.g, max ) ); + ret.b = std::max( min, std::min( p.b, max ) ); + return ret; + }; + + // Just clamping now + glm::vec3 p = Clamp( mNextFrame->At( x, y ), 1.0f, 0.0f ); + + // Gamma correction + static const float Gamma = 1.0f / 2.2f; + + olc::Pixel pix( + (uint8_t)( pow( p.r, Gamma ) * 255.0f ), + (uint8_t)( pow( p.g, Gamma ) * 255.0f ), + (uint8_t)( pow( p.b, Gamma ) * 255.0f ) ); + + DrawRect( x, y, 1, 1, pix ); + } mNextFrame = nullptr; mNewFrame = false; diff --git a/src/display.hpp b/src/display.hpp index 5f80f66..0b8e809 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -24,7 +24,7 @@ struct DisplayBuff // for the time being NEEDS to run on main thread class Display : public olc::PixelGameEngine { - +public: Display(); void Init( int x, int y ); void Init( int x, int y, std::string title ); diff --git a/src/main.cpp b/src/main.cpp index c2decdf..1a5215b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,32 +1,39 @@ #define OLC_PGE_APPLICATION -class Application : public olc::PixelGameEngine +#include "display.hpp" + +#include +#include + +void EngineThread( Aeon::Display* disp ) { -public: - Application() + Aeon::DisplayBuff buf( 500, 500 ); + while ( true ) { - sAppName = "2D Global Illumination"; + + for ( int x = 0; x < 500; x++ ) + for ( int y = 0; y < 500; y++ ) + buf.Set( x, y, { (float)( rand() % 255 ) / 255.0f, + (float)( rand() % 255 ) / 255.0f, + (float)( rand() % 255 ) / 255.0f } ); + + disp->NewFrame( &buf ); + + static std::chrono::milliseconds dura( 10 ); + std::this_thread::sleep_for( dura ); } - - bool OnUserCreate() override - { - return true; - } - - bool OnUserUpdate( float fElapsedTime ) override - { - for ( int x = 0; x < ScreenWidth(); x++ ) - for ( int y = 0; y < ScreenHeight(); y++ ) - Draw( x, y, olc::Pixel( x % 255, y % 255, rand() % 255 ) ); - - return true; - } - -}; +} int main( int argc, char** argv ) { - Application app; - if ( app.Construct( 700, 700, 1, 1, false, true ) ) - app.Start(); + Aeon::Display display; + + display.Init( 500, 500 ); + display.SetTitle( "BRuh" ); + + std::thread thread( EngineThread, &display ); + + display.Start(); + + thread.detach(); } diff --git a/src/poly.cpp b/src/poly.cpp index 3b2eee0..e5cde75 100644 --- a/src/poly.cpp +++ b/src/poly.cpp @@ -22,6 +22,7 @@ int Polygon::AddSide( Segment segment ) { mIterator++; mSides[mIterator] = segment; + return mIterator; } void Polygon::RemoveSide( int segment )