From d69354ea0980cecfedef1044c0443e581cc13cb3 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Sun, 28 Jul 2024 19:10:48 -0400 Subject: [PATCH] working texture? --- tinyrender3_homework/image.go | 4 +++- tinyrender3_homework/main.go | 2 +- tinyrender3_homework/render.go | 2 +- tinyrender3_homework/run.sh | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tinyrender3_homework/image.go b/tinyrender3_homework/image.go index 6267ccb..33d17f0 100644 --- a/tinyrender3_homework/image.go +++ b/tinyrender3_homework/image.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "image/color" + //"log" "math" "strings" ) @@ -15,7 +16,8 @@ func Col2Uint(r, g, b byte) uint { func Color2Uint(col color.Color) uint { r, g, b, _ := col.RGBA() - return uint((r << 16) | (g << 8) | b) + //log.Print(r, g, b) + return uint(((r & 0xff00) << 8) | (g & 0xff00) | ((b & 0xff00) >> 8)) } // Convert uint to rgb (in that order) diff --git a/tinyrender3_homework/main.go b/tinyrender3_homework/main.go index 23117fe..236dd60 100644 --- a/tinyrender3_homework/main.go +++ b/tinyrender3_homework/main.go @@ -111,7 +111,7 @@ func main() { n = n.Normalize() intensity := n.MultSimp(&light) if intensity > 0 { - Triangle3t(&fb, texture, intensity, byte(255*intensity), byte(255*intensity)), sc[0], sc[1], sc[2]) + Triangle3t(&fb, texture, intensity, sc[0], sc[1], sc[2]) //Triangle3(&fb, uint(rand.Int()), sc[0], sc[1], sc[2]) //Triangle1(&fb, uint(rand.Int()), sc[0].ToVec2i(), sc[1].ToVec2i(), sc[2].ToVec2i()) //Triangle2(&fb, 0xFFFFFF, sc[0], sc[1], sc[2]) diff --git a/tinyrender3_homework/render.go b/tinyrender3_homework/render.go index 0bedb7d..154cdc3 100644 --- a/tinyrender3_homework/render.go +++ b/tinyrender3_homework/render.go @@ -326,7 +326,7 @@ func Triangle3t(fb *Framebuffer, texture image.Image, intensity float32, v0v Ver //log.Print(pz) fb.ZBuffer[x+y*fb.Width] = pz txo := int(float32(tw) * (w0a*v0v.Tex.X + w1a*v1v.Tex.X + w2a*v2v.Tex.X)) - tyo := int(float32(th) * (w0a*v0v.Tex.Y + w1a*v1v.Tex.Y + w2a*v2v.Tex.Y)) + tyo := int(float32(th) * (1 - (w0a*v0v.Tex.Y + w1a*v1v.Tex.Y + w2a*v2v.Tex.Y))) col := texture.At(tx+txo, ty+tyo) //c := texture.At() fb.Set(x, y, Color2Uint(col)) //uint(texture.Bounds().Dx()) diff --git a/tinyrender3_homework/run.sh b/tinyrender3_homework/run.sh index 44c7f64..54af6fc 100755 --- a/tinyrender3_homework/run.sh +++ b/tinyrender3_homework/run.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -e + if [ $# -ne 1 ]; then echo "You must pass the basename for the .prof and .ppm" exit 1