Modulo and negative parameters for arrays?

Started by
0 comments, last by Lode 21 years, 8 months ago
When trying to make a texturing algorithm for a raytracer, I got a 32*32 array for a texture and did some calculations to see what pixel of the array I must call. The texture array had ONLY pixels with color black and fully bright red but one of the many failed attempts of the algorithm showed up OTHER COLORS!!!! :o These other colors were darker red (no other colors because the texture only had a red channel). Here's a screenshot of this scary stuff: I got the textures working properly now but I still don't understand why: I take modulo %32 of an integer, so the result should be between 0 and 31, is that right? Or does it give problems for numbers < 0? Then I use the result as parameter for a 32x32 array so that should never give problems, right? But then why doesn't my program give an error and shows me some weird stuff that I know are not inside the array? Was I seeing other memory locations? [edited by - Lode on July 29, 2002 9:58:23 AM]
Advertisement
I don''t know if compilers in general handles mod the same way, but VC++ doesn''t turn negative numbers into positive when taking the modulus. In effect -13%10 = -3.

-Neophyte

This topic is closed to new replies.

Advertisement