3dtrial/tinyrender1/main.go

54 lines
1.0 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/pprof" // For performance whatever
)
const (
Width = 512
Height = 512
)
func must(err error) {
if err != nil {
panic(err)
}
}
// However flag works... idk
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
func main() {
log.Printf("Program start")
// Little section for doing cpu profiling. I guess that's all you have to do?
flag.Parse()
if *cpuprofile != "" {
log.Printf("CPU profiling requested, write to %s", *cpuprofile)
f, err := os.Create(*cpuprofile)
must(err)
defer f.Close()
err = pprof.StartCPUProfile(f)
must(err)
defer pprof.StopCPUProfile()
}
fb := NewFramebuffer(Width, Height)
log.Printf("Running render")
// Just draw a simple line
LineDumb(&fb, 0xFFFFFF, 100, 100, 350, 200)
LineDumb2(&fb, 0xFF0000, 120, 100, 200, 350)
LineDumb2(&fb, 0xFF0000, 350, 200, 100, 100) // backward first line
log.Printf("Exporting ppm to stdout")
fmt.Print(fb.ExportPPM())
log.Printf("Program end")
}