Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev/msvc/olcPGE3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<ClInclude Include="..\..\utilities\olcUTIL3_GameMode.h" />
<ClInclude Include="..\..\utilities\olcUTIL3_Geometry2D.h" />
<ClInclude Include="..\..\utilities\olcUTIL3_QuadTree.h" />
<ClInclude Include="..\..\utilities\olcUTIL3_SWRender.h" />
<ClInclude Include="..\src\api_macos.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down
3 changes: 3 additions & 0 deletions dev/msvc/olcPGE3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
<ClInclude Include="..\..\extensions\miniaudio\olcPGEX3_Miniaudio.h">
<Filter>Extensions\MiniAudio</Filter>
</ClInclude>
<ClInclude Include="..\..\utilities\olcUTIL3_SWRender.h">
<Filter>Utilities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\core.cpp">
Expand Down
12 changes: 10 additions & 2 deletions dev/msvc/olcPGE3_BuildSH/olcPGE3_BuildSH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\examples\olcPGE3_SoftwareRendering.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\examples\olcPGE3_TextFontMap.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -164,8 +168,8 @@
<ClCompile Include="..\..\..\examples\olcPGE3_Camera2D_Tiles.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\examples\olcPGE3_Touch.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -242,15 +246,19 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)..\..\</OutDir>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../../;</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)..\..\</OutDir>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../../;</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)..\..\</OutDir>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../../;</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)..\..\</OutDir>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../../;</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
3 changes: 3 additions & 0 deletions dev/msvc/olcPGE3_BuildSH/olcPGE3_BuildSH.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
<ClCompile Include="..\..\..\examples\olcPGE3_Touch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\examples\olcPGE3_SoftwareRendering.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\..\examples\assets\minsanity_texture.png">
Expand Down
31 changes: 31 additions & 0 deletions dev/src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,37 @@ namespace olc
return onCPU;
}

bool Image::set(int x, int y, olc::Pixel p)
{
if (x >= 0 && y >= 0 && x < dimensions.x && y < dimensions.y)
{
pixels[int(y) * dimensions.x + int(x)] = p;
return true;
}
else
return false;
}

olc::Pixel Image::get(int x, int y)
{
if (x >= 0 && y >= 0 && x < dimensions.x && y < dimensions.y)
{
return pixels[int(y) * dimensions.x + int(x)];
}
else
return olc::Colour::BLACK;
}

int Image::width()
{
return dimensions.x;
}

int Image::height()
{
return dimensions.y;
}

olc::ImageRegion Image::all()
{
return olc::ImageRegion(*this);
Expand Down
7 changes: 7 additions & 0 deletions dev/src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ namespace olc
bool BoundToGPU() const;
bool BoundToCPU() const;


// SW Renderer IFace
bool set(int x, int y, olc::Pixel p);
olc::Pixel get(int x, int y);
int width();
int height();

public:
olc::ImageRegion all();
olc::ImageRegion region(const olc::vf2d pos, const olc::vf2d& size);
Expand Down
200 changes: 200 additions & 0 deletions examples/olcPGE3_SoftwareRendering.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
olc::PixelGameEngine3 Example - Software Rendering

Draws transformed and textured graphics entirely with the CPU

Licenced under the OLC-3 License
*/


// Define OLC_PGE3_APPLICATION to include the implementation of
// the Pixel Game Engine as part of this translation unit
#define OLC_PGE3_APPLICATION
#include "../olcPixelGameEngine3.h"
#include "../utilities/olcUTIL3_SWRender.h"

struct TextSurface
{
TextSurface()
{
sSurface.resize(vSize.area(), '-');
}

std::string sSurface;
olc::vi2d vSize = { 32, 30 };

bool set(int x, int y, char c)
{
if (x >= 0 && y >= 0 && x < vSize.x && y < vSize.y)
{
sSurface[y * vSize.x + x] = c;
return true;
}
else
return false;
}

char get(int x, int y)
{
if (x >= 0 && y >= 0 && x < vSize.x && y < vSize.y)
{
return sSurface[y * vSize.x + x];
}
else
return 'x';
}

int width() { return vSize.x; }
int height() { return vSize.y; }
};



class Example_SoftwareRenderer : public olc::PixelGameEngine
{
public:
Example_SoftwareRenderer()
{
sAppName = "Example - Lines";
}

public:
// Called once at the start, so create things here
bool OnUserCreate() override
{
// Nothing to do here, so return true
CreateImageFromFile(imgTest, "./assets/sanity_texture.png");
return true;
}

// Called every frame, so update things here
bool OnUserUpdate(float fElapsedTime) override
{

draw.Clear(olc::Colour::CYAN);
draw.Pixel({ 0,0 },olc::Colour::GREEN);

DrawSW.SetTarget(draw.GetTarget());

DrawSW.Clear(olc::Colour::VERY_DARK_BLUE);

DrawSW.Plot({ 4, 4 }, olc::Colour::RED);

DrawSW.Line({ 10,4 }, mouse.GetPosition(), olc::Colour::MAGENTA, olc::Colour::VERY_DARK_BLUE);

DrawSW.FilledRect({ 10,22 }, { 32, 32 }, olc::Colour::BLACK);

DrawSW.FilledRect({ 6, 18 }, { 32, 32 },
olc::Colour::RED, olc::Colour::YELLOW,
olc::Colour::GREEN, olc::Colour::MAGENTA);

DrawSW.Rect({ 6, 18 }, { 32, 32 }, olc::Colour::WHITE);



float fTotal = float(TotalTimeElapsed());

DrawSW.WorldOffset({ 68, 68 });
DrawSW.WorldRotate(fTotal, { 0 ,0 });
DrawSW.FilledRect({ -16, -16 }, { 32, 32 }, olc::Colour::BLACK);

DrawSW.WorldReset();
DrawSW.WorldOffset({ 64, 64 });
DrawSW.WorldRotate(fTotal, { 0 ,0 });
DrawSW.FilledRect({ -16, -16 }, { 32, 32 },
olc::Colour::RED, olc::Colour::YELLOW,
olc::Colour::GREEN, olc::Colour::MAGENTA);

DrawSW.Rect({ -16, -16 }, { 32, 32 }, olc::Colour::WHITE);


DrawSW.WorldReset();
DrawSW.WorldOffset({ 128, 68 });
DrawSW.WorldRotate(fTotal, { 0 ,0 });
DrawSW.WorldScale({ 2, 2 });
DrawSW.FilledRect({ -16, -16 }, { 32, 32 }, olc::Colour::BLACK);

DrawSW.WorldReset();
DrawSW.WorldOffset({ 124, 64 });
DrawSW.WorldRotate(fTotal, { 0 ,0 });
DrawSW.WorldScale({ 2, 2 });
DrawSW.TexturedRect({ -16, -16 }, { 32, 32 },
imgTest);





DrawSW.WorldReset();
DrawSW.TexturedTriangle(
{ 20,180 },
mouse.GetPosition(),
{ 250, 230 },
olc::Colour::RED,
olc::Colour::GREEN,
olc::Colour::BLUE,
{ 0,0 },
{ 1,0 },
{ 1,1 }, imgTest);



DrawSW.Circle(mouse.GetPosition(), 20, olc::Colour::GREEN);
DrawSW.FilledCircle(mouse.GetPosition(), 10, olc::Colour::CYAN);


//// Clear
//TextDraw.SetTarget(textSurface);
//
//
//TextDraw.Clear('-');


//TextDraw.FilledTriangle(
// { 20 / 8, 180 / 8 },
// mouse.GetPosition() / 8,
// { 250 / 8, 230 / 8 },
// 'O');


//TextDraw.Line({ 10 / 8,10 / 8 }, mouse.GetPosition() / 8, 'A');


//// Draw TextSurface to Screen
//for (int y = 0; y < textSurface.height(); y++)
//{
// for (int x = 0; x < textSurface.width(); x++)
// {
// draw.String({ x * 8.0f, y * 8.0f }, std::string(1, textSurface.get(x, y)));
// }
//}

// Successful frame
return true;
}

protected:
olc::utils::SWDraw DrawSW;
olc::Image imgTest;

TextSurface textSurface;
olc::utils::SoftwareRenderer<TextSurface, char> TextDraw;
};


// Main entry point for the application
int main()
{
// Construct demo application
Example_SoftwareRenderer demo;

// Create "screen" of 256x240 "pixels"
// with a pixel size of 4x4 actual screen pixels
if (demo.Construct({ 256, 240 }, { 4, 4 }))
{
// Start the application
demo.Start();
}

return 0;
}
38 changes: 38 additions & 0 deletions olcPixelGameEngine3.h
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,13 @@ namespace olc
bool BoundToGPU() const;
bool BoundToCPU() const;


// SW Renderer IFace
bool set(int x, int y, olc::Pixel p);
olc::Pixel get(int x, int y);
int width();
int height();

public:
olc::ImageRegion all();
olc::ImageRegion region(const olc::vf2d pos, const olc::vf2d& size);
Expand Down Expand Up @@ -20668,6 +20675,37 @@ namespace olc
return onCPU;
}

bool Image::set(int x, int y, olc::Pixel p)
{
if (x >= 0 && y >= 0 && x < dimensions.x && y < dimensions.y)
{
pixels[int(y) * dimensions.x + int(x)] = p;
return true;
}
else
return false;
}

olc::Pixel Image::get(int x, int y)
{
if (x >= 0 && y >= 0 && x < dimensions.x && y < dimensions.y)
{
return pixels[int(y) * dimensions.x + int(x)];
}
else
return olc::Colour::BLACK;
}

int Image::width()
{
return dimensions.x;
}

int Image::height()
{
return dimensions.y;
}

olc::ImageRegion Image::all()
{
return olc::ImageRegion(*this);
Expand Down
Loading
Loading