It all works but damn its slowwww
This commit is contained in:
@@ -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() );
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
53
src/main.cpp
53
src/main.cpp
@@ -1,32 +1,39 @@
|
||||
#define OLC_PGE_APPLICATION
|
||||
|
||||
class Application : public olc::PixelGameEngine
|
||||
#include "display.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ int Polygon::AddSide( Segment segment )
|
||||
{
|
||||
mIterator++;
|
||||
mSides[mIterator] = segment;
|
||||
return mIterator;
|
||||
}
|
||||
|
||||
void Polygon::RemoveSide( int segment )
|
||||
|
||||
Reference in New Issue
Block a user