From 994c30ab2cfe531475ab360595ef6e2d5335bd1e Mon Sep 17 00:00:00 2001
From: Javidx9 <25419386+OneLoneCoder@users.noreply.github.com>
Date: Wed, 23 Sep 2026 21:44:02 +0100
Subject: [PATCH] Added SetPixel(), SetRawPixel() & SetUnsafeRawPixel()
---
dev/msvc/olcPGE3.vcxproj | 2 +
dev/msvc/olcPGE3.vcxproj.filters | 6 +++
dev/src/draw.cpp | 41 +++++++++++++++++
dev/src/draw.h | 35 +++++++++++++++
olcPixelGameEngine3.h | 76 ++++++++++++++++++++++++++++++++
5 files changed, 160 insertions(+)
diff --git a/dev/msvc/olcPGE3.vcxproj b/dev/msvc/olcPGE3.vcxproj
index fcff341..ab6ff8e 100644
--- a/dev/msvc/olcPGE3.vcxproj
+++ b/dev/msvc/olcPGE3.vcxproj
@@ -176,6 +176,7 @@
+
@@ -276,6 +277,7 @@
+
true
true
diff --git a/dev/msvc/olcPGE3.vcxproj.filters b/dev/msvc/olcPGE3.vcxproj.filters
index 03573c3..04da150 100644
--- a/dev/msvc/olcPGE3.vcxproj.filters
+++ b/dev/msvc/olcPGE3.vcxproj.filters
@@ -198,6 +198,9 @@
Hosts\wxWidgets Specific
+
+ Extensions\MiniAudio
+
@@ -278,6 +281,9 @@
Hosts\wxWidgets Specific
+
+ Extensions\MiniAudio
+
diff --git a/dev/src/draw.cpp b/dev/src/draw.cpp
index f3e19c4..86660a5 100644
--- a/dev/src/draw.cpp
+++ b/dev/src/draw.cpp
@@ -254,11 +254,27 @@ olc::Pixel olc::Draw::GetPixel(olc::Image& image, const olc::vf2d& pos, const ol
return failcol;
}
+void olc::Draw::SetPixel(olc::Image& image, const olc::vf2d& pos, const olc::Pixel col)
+{
+ // Check if in bounds
+ olc::vf2d tpos = transformAffine.forwardRound(pos);
+ if (tpos.x >= 0 && tpos.y >= 0 && tpos.x < float(pTarget->Size().x) && tpos.y < float(pTarget->Size().y))
+ {
+ PrepareImageForSW(image);
+ pTarget->Pixel(tpos) = col;
+ }
+}
+
olc::Pixel olc::Draw::GetPixel(const olc::vf2d& pos, const olc::Pixel failcol)
{
return GetPixel(GetTarget(), pos, failcol);
}
+void olc::Draw::SetPixel(const olc::vf2d& pos, const olc::Pixel col)
+{
+ SetPixel(GetTarget(), pos, col);
+}
+
olc::Pixel olc::Draw::GetRawPixel(olc::Image& image, const olc::vi2d& pos, const olc::Pixel failcol)
{
if (pos.x >= 0 && pos.y >= 0 && pos.x < float(image.Size().x) && pos.y < float(image.Size().y))
@@ -270,22 +286,47 @@ olc::Pixel olc::Draw::GetRawPixel(olc::Image& image, const olc::vi2d& pos, const
return failcol;
}
+void olc::Draw::SetRawPixel(olc::Image& image, const olc::vi2d& pos, const olc::Pixel col)
+{
+ if (pos.x >= 0 && pos.y >= 0 && pos.x < float(image.Size().x) && pos.y < float(image.Size().y))
+ {
+ PrepareImageForSW(image);
+ image.Pixel(pos) = col;
+ }
+}
+
olc::Pixel olc::Draw::GetRawPixel(const olc::vi2d& pos, const olc::Pixel failcol)
{
return GetRawPixel(GetTarget(), pos, failcol);
}
+void olc::Draw::SetRawPixel(const olc::vi2d& pos, const olc::Pixel col)
+{
+ SetRawPixel(GetTarget(), pos, col);
+}
+
olc::Pixel olc::Draw::GetUnsafeRawPixel(olc::Image& image, const olc::vi2d& pos)
{
PrepareImageForSW(image);
return image.Pixel(pos);
}
+void olc::Draw::SetUnsafeRawPixel(olc::Image& image, const olc::vi2d& pos, const olc::Pixel col)
+{
+ PrepareImageForSW(image);
+ image.Pixel(pos) = col;
+}
+
olc::Pixel olc::Draw::GetUnsafeRawPixel(const olc::vi2d& pos)
{
return GetUnsafeRawPixel(GetTarget(), pos);
}
+void olc::Draw::SetUnsafeRawPixel(const olc::vi2d& pos, const olc::Pixel col)
+{
+ SetUnsafeRawPixel(GetTarget(), pos, col);
+}
+
void olc::Draw::Clear(const olc::Pixel& col)
{
PrepareTargetForHW();
diff --git a/dev/src/draw.h b/dev/src/draw.h
index dcdac67..e082107 100644
--- a/dev/src/draw.h
+++ b/dev/src/draw.h
@@ -233,37 +233,72 @@ namespace olc
const olc::Pixel col = olc::Colour::WHITE,
const olc::Pixel tint = olc::Colour::WHITE);
+ // Lower-Level Pixel Manipulation
+
// Read a pixel from an image (guarantees fresh)
olc::Pixel GetPixel(
olc::Image& image,
const olc::vf2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write a pixel to an image
+ void SetPixel(
+ olc::Image& image,
+ const olc::vf2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read a pixel from target image (guarantees fresh)
olc::Pixel GetPixel(
const olc::vf2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write a pixel to target image
+ void SetPixel(
+ const olc::vf2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from an image (guarantees fresh)
olc::Pixel GetRawPixel(
olc::Image& image,
const olc::vi2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write an untransformed pixel to an image
+ void SetRawPixel(
+ olc::Image& image,
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from target image (guarantees fresh)
olc::Pixel GetRawPixel(
const olc::vi2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write an untransformed pixel to target image
+ void SetRawPixel(
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from a target image with no bounds checking (gurantees fresh)
olc::Pixel GetUnsafeRawPixel(
olc::Image& image,
const olc::vi2d& pos);
+ // Write an untransformed pixel to a target image with no bounds checking
+ void SetUnsafeRawPixel(
+ olc::Image& image,
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from target image with no bounds checking (gurantees fresh)
olc::Pixel GetUnsafeRawPixel(
const olc::vi2d& pos);
+ // Write an untransformed pixel to target image with no bounds checking
+ void SetUnsafeRawPixel(
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Clear entire draw target to specific colour
void Clear(const olc::Pixel& col);
diff --git a/olcPixelGameEngine3.h b/olcPixelGameEngine3.h
index 59ce5c0..a5edfe0 100644
--- a/olcPixelGameEngine3.h
+++ b/olcPixelGameEngine3.h
@@ -2909,37 +2909,72 @@ namespace olc
const olc::Pixel col = olc::Colour::WHITE,
const olc::Pixel tint = olc::Colour::WHITE);
+ // Lower-Level Pixel Manipulation
+
// Read a pixel from an image (guarantees fresh)
olc::Pixel GetPixel(
olc::Image& image,
const olc::vf2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write a pixel to an image
+ void SetPixel(
+ olc::Image& image,
+ const olc::vf2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read a pixel from target image (guarantees fresh)
olc::Pixel GetPixel(
const olc::vf2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write a pixel to target image
+ void SetPixel(
+ const olc::vf2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from an image (guarantees fresh)
olc::Pixel GetRawPixel(
olc::Image& image,
const olc::vi2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write an untransformed pixel to an image
+ void SetRawPixel(
+ olc::Image& image,
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from target image (guarantees fresh)
olc::Pixel GetRawPixel(
const olc::vi2d& pos,
const olc::Pixel failcol = olc::Colour::BLACK);
+ // Write an untransformed pixel to target image
+ void SetRawPixel(
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from a target image with no bounds checking (gurantees fresh)
olc::Pixel GetUnsafeRawPixel(
olc::Image& image,
const olc::vi2d& pos);
+ // Write an untransformed pixel to a target image with no bounds checking
+ void SetUnsafeRawPixel(
+ olc::Image& image,
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Read an untransformed pixel from target image with no bounds checking (gurantees fresh)
olc::Pixel GetUnsafeRawPixel(
const olc::vi2d& pos);
+ // Write an untransformed pixel to target image with no bounds checking
+ void SetUnsafeRawPixel(
+ const olc::vi2d& pos,
+ const olc::Pixel col = olc::Colour::WHITE);
+
// Clear entire draw target to specific colour
void Clear(const olc::Pixel& col);
@@ -18249,11 +18284,27 @@ olc::Pixel olc::Draw::GetPixel(olc::Image& image, const olc::vf2d& pos, const ol
return failcol;
}
+void olc::Draw::SetPixel(olc::Image& image, const olc::vf2d& pos, const olc::Pixel col)
+{
+ // Check if in bounds
+ olc::vf2d tpos = transformAffine.forwardRound(pos);
+ if (tpos.x >= 0 && tpos.y >= 0 && tpos.x < float(pTarget->Size().x) && tpos.y < float(pTarget->Size().y))
+ {
+ PrepareImageForSW(image);
+ pTarget->Pixel(tpos) = col;
+ }
+}
+
olc::Pixel olc::Draw::GetPixel(const olc::vf2d& pos, const olc::Pixel failcol)
{
return GetPixel(GetTarget(), pos, failcol);
}
+void olc::Draw::SetPixel(const olc::vf2d& pos, const olc::Pixel col)
+{
+ SetPixel(GetTarget(), pos, col);
+}
+
olc::Pixel olc::Draw::GetRawPixel(olc::Image& image, const olc::vi2d& pos, const olc::Pixel failcol)
{
if (pos.x >= 0 && pos.y >= 0 && pos.x < float(image.Size().x) && pos.y < float(image.Size().y))
@@ -18265,22 +18316,47 @@ olc::Pixel olc::Draw::GetRawPixel(olc::Image& image, const olc::vi2d& pos, const
return failcol;
}
+void olc::Draw::SetRawPixel(olc::Image& image, const olc::vi2d& pos, const olc::Pixel col)
+{
+ if (pos.x >= 0 && pos.y >= 0 && pos.x < float(image.Size().x) && pos.y < float(image.Size().y))
+ {
+ PrepareImageForSW(image);
+ image.Pixel(pos) = col;
+ }
+}
+
olc::Pixel olc::Draw::GetRawPixel(const olc::vi2d& pos, const olc::Pixel failcol)
{
return GetRawPixel(GetTarget(), pos, failcol);
}
+void olc::Draw::SetRawPixel(const olc::vi2d& pos, const olc::Pixel col)
+{
+ SetRawPixel(GetTarget(), pos, col);
+}
+
olc::Pixel olc::Draw::GetUnsafeRawPixel(olc::Image& image, const olc::vi2d& pos)
{
PrepareImageForSW(image);
return image.Pixel(pos);
}
+void olc::Draw::SetUnsafeRawPixel(olc::Image& image, const olc::vi2d& pos, const olc::Pixel col)
+{
+ PrepareImageForSW(image);
+ image.Pixel(pos) = col;
+}
+
olc::Pixel olc::Draw::GetUnsafeRawPixel(const olc::vi2d& pos)
{
return GetUnsafeRawPixel(GetTarget(), pos);
}
+void olc::Draw::SetUnsafeRawPixel(const olc::vi2d& pos, const olc::Pixel col)
+{
+ SetUnsafeRawPixel(GetTarget(), pos, col);
+}
+
void olc::Draw::Clear(const olc::Pixel& col)
{
PrepareTargetForHW();