render: model: Invert texture V coords when parsing OBJ files.
authorDavid Thompson <dthompson2@worcester.edu>
Tue, 29 Oct 2019 21:17:19 +0000 (17:17 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Tue, 29 Oct 2019 21:17:19 +0000 (17:17 -0400)
chickadee/render/model.scm

index 332d211..9f29240 100644 (file)
                               ((u)
                                (vec2 (string->number u) 0.0))
                               ((u v)
-                               (vec2 (string->number u) (string->number v)))
+                               ;; OBJ texture coordinates use the
+                               ;; top-left of the image as the origin,
+                               ;; but OpenGL uses the bottom-left, so
+                               ;; all V values must be inverted.
+                               (vec2 (string->number u)
+                                     (- 1.0 (string->number v))))
                               ((u v w)
                                (vec2 (string->number u)
-                                     (string->number v)))
+                                     (- 1.0 (string->number v))))
                               (_
                                (parse-error "wrong number of texcoord arguments" args)))))
         (define (parse-normal args)