summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2026-01-01 09:49:59 -0800
committer3gg <3gg@shellblade.net>2026-01-01 09:49:59 -0800
commit7e48c57e1c76d4ef874a2e15bfe9fd43e33f60a8 (patch)
tree2e6f9435c62ef5212a41ff4d0ae952a0408bb98f
parent7b9162ea7f4c78aa56a4a73187b22593b5d54913 (diff)
Notes on coordinate systems
-rw-r--r--include/swgfx.h14
-rw-r--r--src/swgfx.c2
2 files changed, 10 insertions, 6 deletions
diff --git a/include/swgfx.h b/include/swgfx.h
index 4a98116..d1f56df 100644
--- a/include/swgfx.h
+++ b/include/swgfx.h
@@ -2,10 +2,16 @@
2Software rendering library. 2Software rendering library.
3 3
4Coordinate systems: 4Coordinate systems:
5- Pixel coordinates (i,j) refer to the center of the pixel. 5- The coordinate systems for image addressing and texture sampling are the same
6 Thus, real-valued coordinates (x,y) with no fractional part point at the pixel center. 6 except in scale.
7- Viewport origin is the top-left corner of the screen. 7 Origin is in the top-left corner of the image.
8 The viewport axes extend down and to the right. 8 Axes extend down and to the right.
9- Image addressing:
10 (i,j) integer coordinates refer to the center of the pixel.
11- Texture addressing:
12 (u,v) range in [0,1].
13 (0,0) is the center of the top-left pixel.
14 (1,1) is the center of the bottom-right pixel.
9 15
10Multi-threading: 16Multi-threading:
11- Internal resources (swgfx context) are externally synchronized. 17- Internal resources (swgfx context) are externally synchronized.
diff --git a/src/swgfx.c b/src/swgfx.c
index 3bec663..7ade051 100644
--- a/src/swgfx.c
+++ b/src/swgfx.c
@@ -272,8 +272,6 @@ void SetDepth(swgfx* gfx, const sgVec2i p, R depth) {
272sgPixel Sample(const sgTexture_t* texture, sgVec2 uv) { 272sgPixel Sample(const sgTexture_t* texture, sgVec2 uv) {
273 assert(texture); 273 assert(texture);
274 assert(texture->pixels); 274 assert(texture->pixels);
275 // TODO: (1/2, 1/2) is the center of the pixel. Do we need to do something
276 // about it here?
277#define INDEX(X,Y) texture->pixels[(Y) * texture->width + (X)] 275#define INDEX(X,Y) texture->pixels[(Y) * texture->width + (X)]
278 // Doing a nearest sample for now. TODO: Other sampling strategies. 276 // Doing a nearest sample for now. TODO: Other sampling strategies.
279 const int x = (int)(uv.x * (R)texture->width); 277 const int x = (int)(uv.x * (R)texture->width);