diff --git a/programs/make.sh b/programs/make.sh index 3d9b92e..8e6b1ba 100755 --- a/programs/make.sh +++ b/programs/make.sh @@ -1,6 +1,6 @@ #!/bin/bash -PROGRAM=helloTerminal +PROGRAM=test -clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM +clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-unused-parameter -Wno-missing-field-initializers -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM #clear; clear; clang -x c -g -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM diff --git a/programs/test.c b/programs/test.c index ccd33c0..4b43cba 100644 --- a/programs/test.c +++ b/programs/test.c @@ -1,4 +1,4 @@ -/* +/** Some basic tests for small3dlib. author: Miloslav Ciz @@ -6,6 +6,8 @@ */ #include +#include +#include #define S3L_PIXEL_FUNCTION pixelFunc #define S3L_RESOLUTION_X 100 @@ -81,7 +83,7 @@ int testTriangleRasterization( return numErrors; } -int testRasterization() +int testRasterization(void) { printf("\n=== TESTING RASTERIZATION ===\n"); @@ -337,7 +339,7 @@ int testRasterization() return numErrors; } -static inline double abs(double a) +static inline double absVal(double a) { return a >= 0.0 ? a : (-1 * a); } @@ -350,7 +352,7 @@ double vec3Len(S3L_Vec4 v) ((double) v.z) * ((double) v.z)); } -int testGeneral() +int testGeneral(void) { printf("\n=== TESTING GENERAL ===\n"); @@ -362,9 +364,9 @@ int testGeneral() uint32_t errors0 = 0; uint32_t errors1 = 0; - for (S3L_Unit x = -1 * m; x < m; x += 3 * (abs(x) / 64 + 1)) - for (S3L_Unit y = -1 * m; y < m; y += 3 * (abs(y) / 32 + 1)) - for (S3L_Unit z = -1 * m; z < m; z += 5 * (abs(z) / 64 + 1)) + for (S3L_Unit x = -1 * m; x < m; x += 3 * (absVal(x) / 64 + 1)) + for (S3L_Unit y = -1 * m; y < m; y += 3 * (absVal(y) / 32 + 1)) + for (S3L_Unit z = -1 * m; z < m; z += 5 * (absVal(z) / 64 + 1)) { S3L_Vec4 v; @@ -372,13 +374,13 @@ int testGeneral() S3L_normalizeVec3Fast(&v); double l0 = vec3Len(v); - double e0 = abs(l0 - S3L_FRACTIONS_PER_UNIT); + double e0 = absVal(l0 - S3L_FRACTIONS_PER_UNIT); S3L_setVec4(&v,x,y,z,0); S3L_normalizeVec3(&v); double l1 = vec3Len(v); - double e1 = abs(l1 - S3L_FRACTIONS_PER_UNIT); + double e1 = absVal(l1 - S3L_FRACTIONS_PER_UNIT); if (e0 > tolerance) errors0++; @@ -397,8 +399,19 @@ int testGeneral() return errors1; } -int main() +int testRender(void) { + printf("\n=== TESTING RENDER ===\n"); + + // TODO + + return 0; +} + +int main(void) +{ + printf("testing small3dlib\n\n"); + S3L_Mat4 m, m2; S3L_Vec4 v; @@ -420,8 +433,9 @@ int main() uint32_t totalErrors = 0; - totalErrors += testRasterization(); totalErrors += testGeneral(); + totalErrors += testRasterization(); + totalErrors += testRender(); printf("\n===== DONE =====\ntotal errors: %d\n",totalErrors); diff --git a/small3dlib.h b/small3dlib.h index debc7ec..4f6fbb1 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -22,6 +22,9 @@ z-buffer (full or reduced, S3L_Z_BUFFER), sorted-drawing (S3L_SORT), or even none of these. See the description of the options in this file. + The rendering itself is done with S3L_drawScene, usually preceded by + S3L_newFrame (for clearing zBuffer etc.). + The library is meant to be used in not so huge programs that use single translation unit and so includes both declarations and implementation at once. If you for some reason use multiple translation units (which include the @@ -681,10 +684,10 @@ void S3L_drawTriangle( /** This should be called before rendering each frame. The function clears buffers and does potentially other things needed for the frame. */ -void S3L_newFrame(); +void S3L_newFrame(void); -void S3L_zBufferClear(); -void S3L_stencilBufferClear(); +void S3L_zBufferClear(void); +void S3L_stencilBufferClear(void); /** Writes a value (not necessarily depth! depends on the format of z-buffer) to z-buffer (if enabled). Does NOT check boundaries! */ @@ -1803,7 +1806,7 @@ void S3L_mapProjectionPlaneToScreen( (point.y * S3L_HALF_RESOLUTION_X) / S3L_FRACTIONS_PER_UNIT; } -void S3L_zBufferClear() +void S3L_zBufferClear(void) { #if S3L_Z_BUFFER for (uint32_t i = 0; i < S3L_RESOLUTION_X * S3L_RESOLUTION_Y; ++i) @@ -1811,7 +1814,7 @@ void S3L_zBufferClear() #endif } -void S3L_stencilBufferClear() +void S3L_stencilBufferClear(void) { #if S3L_STENCIL_BUFFER for (uint32_t i = 0; i < S3L_STENCIL_BUFFER_SIZE; ++i) @@ -1819,7 +1822,7 @@ void S3L_stencilBufferClear() #endif } -void S3L_newFrame() +void S3L_newFrame(void) { S3L_zBufferClear(); S3L_stencilBufferClear();