Skip to content

Commit a4537e0

Browse files
committed
bugfix
1 parent 20aeaba commit a4537e0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

our_gl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ void triangle(Vec3i *pts, IShader &shader, TGAImage &image, TGAImage &zbuffer) {
6262
TGAColor color;
6363
for (P.x=bboxmin.x; P.x<=bboxmax.x; P.x++) {
6464
for (P.y=bboxmin.y; P.y<=bboxmax.y; P.y++) {
65-
Vec3f c = barycentric(pts.x, pts.y, pts.z, P);
66-
P.z = std::max(0, std::min(255, int(pts.x.z*c.x + pts.y.z*c.y + pts.z.z*c.z + .5))); // clamping to 0-255 since it is stored in unsigned char
67-
if (c.x<0 || c.y<0 || c.z<0 || zbuffer.get(P.x, P.y).x>P.z) continue;
65+
Vec3f c = barycentric(pts[0], pts[1], pts[2], P);
66+
P.z = std::max(0, std::min(255, int(pts[0].z*c.x + pts[1].z*c.y + pts[2].z*c.z + .5))); // clamping to 0-255 since it is stored in unsigned char
67+
if (c.x<0 || c.y<0 || c.z<0 || zbuffer.get(P.x, P.y)[0]>P.z) continue;
6868
bool discard = shader.fragment(c, color);
6969
if (!discard) {
7070
zbuffer.set(P.x, P.y, TGAColor(P.z));

0 commit comments

Comments
 (0)