terrain working - no culling
[demo] / src / image.cc
index 01ee08f..a99f75a 100644 (file)
@@ -119,4 +119,23 @@ bool Image::load(const char *fname)
 
        img_destroy(&ipm);
        return true;
+}
+
+Vec4 Image::lookup_nearest(float u, float v) const
+{
+       int x = (int)(u * w) % w;
+       int y = (int)(v * h) % h;
+
+       if(is_float) {
+               return ((Vec4*)pixels)[y * w + x];
+       }
+
+       Vec4 color;
+       unsigned char *pptr = ((unsigned char*)pixels) + (y * w + x) * 4;
+       color.x = pptr[0] / 255.0;
+       color.y = pptr[1] / 255.0;
+       color.z = pptr[2] / 255.0;
+       color.w = pptr[3] / 255.0;
+
+       return color;
 }
\ No newline at end of file