From a919b6f1af1a1a1cb3f63dbdf1859bb2253f6c10 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Fri, 21 Apr 2017 18:01:43 +0200 Subject: [PATCH] build C version of raytracer without using c stdlib --- Samples/Raytracer/raytracer.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Samples/Raytracer/raytracer.c b/Samples/Raytracer/raytracer.c index 05a2102e3e..84244f295d 100644 --- a/Samples/Raytracer/raytracer.c +++ b/Samples/Raytracer/raytracer.c @@ -38,10 +38,7 @@ #include -#include -#include #include -#include pascal /* <- pascal calling convention, for no reason in particular except to test the comppiler */ bool hitSphere(float x0, float y0, float z0, float dx, float dy, float dz, float *t) @@ -195,7 +192,7 @@ int main() lxn = lx*lenl, lyn = ly*lenl, lzn = lz*lenl; long startTime = TickCount(); - float *accumV = calloc(sizeof(float), r.right); + float *accumV = (float*)NewPtrClear(sizeof(float) * r.right); for(y = 0; y < r.bottom; y++) { for(x = 0; x < r.right; x++) @@ -263,17 +260,17 @@ int main() } long endTime = TickCount(); - char buf[256]; - unsigned char* pstr = (unsigned char*)buf; - sprintf(buf+1, "pps = %d", (int)( (float)r.right * r.bottom / (endTime - startTime) * 60.0f )); - buf[0] = strlen(buf+1); + Str255 pstr; + NumToString( (long)( (float)r.right * r.bottom / (endTime - startTime) * 60.0f ), + pstr ); - SetRect(&r, 10, 10, 10 + StringWidth(pstr) + 10, 30); + SetRect(&r, 10, 10, 10 + StringWidth("\ppps = ") + StringWidth(pstr) + 10, 30); PaintRect(&r); PenMode(patXor); FrameRect(&r); MoveTo(15,25); TextMode(srcBic); + DrawString("\ppps = "); DrawString(pstr); #if TARGET_API_MAC_CARBON QDFlushPortBuffer(GetWindowPort(win),NULL);