From 7e48c57e1c76d4ef874a2e15bfe9fd43e33f60a8 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 1 Jan 2026 09:49:59 -0800 Subject: Notes on coordinate systems --- include/swgfx.h | 14 ++++++++++---- src/swgfx.c | 2 -- 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 @@ Software rendering library. Coordinate systems: -- Pixel coordinates (i,j) refer to the center of the pixel. - Thus, real-valued coordinates (x,y) with no fractional part point at the pixel center. -- Viewport origin is the top-left corner of the screen. - The viewport axes extend down and to the right. +- The coordinate systems for image addressing and texture sampling are the same + except in scale. + Origin is in the top-left corner of the image. + Axes extend down and to the right. +- Image addressing: + (i,j) integer coordinates refer to the center of the pixel. +- Texture addressing: + (u,v) range in [0,1]. + (0,0) is the center of the top-left pixel. + (1,1) is the center of the bottom-right pixel. Multi-threading: - 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) { sgPixel Sample(const sgTexture_t* texture, sgVec2 uv) { assert(texture); assert(texture->pixels); - // TODO: (1/2, 1/2) is the center of the pixel. Do we need to do something - // about it here? #define INDEX(X,Y) texture->pixels[(Y) * texture->width + (X)] // Doing a nearest sample for now. TODO: Other sampling strategies. const int x = (int)(uv.x * (R)texture->width); -- cgit v1.2.3