From fbab60d89369faa29ee9ac36a39883595a4ea676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 1 Jun 2019 17:58:32 +0200 Subject: [PATCH] Fix bug --- small3dlib.h | 12 ++++++++---- testSDL.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/small3dlib.h b/small3dlib.h index dee5d42..7f18457 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1485,14 +1485,20 @@ void S3L_drawTriangle( } #if S3L_PERSPECTIVE_CORRECTION == 1 - S3L_ScreenCoord i = lXClipped - lX; /* helper var to save one - substraction in the inner loop */ + S3L_ScreenCoord i = lXClipped - lX - 1; /* helper var to save one + substraction in the inner + loop */ #endif // draw the row -- inner loop: for (S3L_ScreenCoord x = lXClipped; x < rXClipped; ++x) { +#if S3L_PERSPECTIVE_CORRECTION == 1 + ++i; /* Has to be done here, because the following tests can skip the + the rest of the loop. */ +#endif + #if S3L_STENCIL_BUFFER if (!S3L_stencilTest(x,p.y)) continue; @@ -1531,8 +1537,6 @@ void S3L_drawTriangle( (lOverZ - S3L_interpolateFrom0(lOverZ,i,rowLength)) * p.depth ) / S3L_FRACTIONS_PER_UNIT; - - i++; #else *barycentric0 = S3L_getFastLerpValue(b0FLS); *barycentric1 = S3L_getFastLerpValue(b1FLS); diff --git a/testSDL.c b/testSDL.c index 0be8351..9ca7109 100644 --- a/testSDL.c +++ b/testSDL.c @@ -11,6 +11,7 @@ #define S3L_PERSPECTIVE_CORRECTION 1 #define S3L_Z_BUFFER 1 +#define S3L_SORT 0 #define S3L_PIXEL_FUNCTION drawPixel @@ -32,6 +33,7 @@ S3L_Scene scene; int8_t keys[256]; const uint8_t testTexture[] = +/* { 2,2,2,0,0,0,2,2,2,2,0,0,0,2,2,2, 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2, @@ -50,6 +52,24 @@ const uint8_t testTexture[] = 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2, 2,2,2,0,0,0,2,2,2,2,0,0,0,2,2,2 }; +*/ +{ + 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0, + 1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1, + 2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2, + 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0, + 1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1, + 2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2, + 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0, + 1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1, + 2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2, + 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0, + 1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1, + 2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2, + 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0, + 1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1, + 2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2 +}; uint32_t pixels[S3L_RESOLUTION_X * S3L_RESOLUTION_Y];