-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdebug.go
60 lines (55 loc) · 1.91 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gltext
import (
"fmt"
"runtime"
)
var IsDebug = false
func DebugPrefix() string {
_, fn, line, _ := runtime.Caller(1)
return fmt.Sprintf("DB: [%s:%d]", fn, line)
}
func TextDebug(message string) {
if IsDebug {
pc, fn, line, _ := runtime.Caller(1)
fmt.Printf("[error] in %s[%s:%d] %s", runtime.FuncForPC(pc).Name(), fn, line, message)
}
}
// PrintVBO prints the individual index locations as well as the texture locations
//
// (0,0) (x1,y1): This shows the layout of the runes. There relative locations to one another can be seen here.
// - If called just after makeBufferData, the left-most x value will start at 0.
// - If called after centerTheData, all indices will have been shifted so that the entire text value is
// centered around the screen's origin of (0,0).
//
// (U,V) (u1,v1) -> (x,y): The (x,y) values refer to pixel locations within the texture
// - Open the texture in an image editor and, using the upper left hand corner as (0,0)
// move to the location (x,y). This is where opengl will pinpoint your rune within the image.
func PrintVBO(vbo []float32, w, h float32) {
if len(vbo)%4 != 0 {
fmt.Println("VBO appears to have an incorrect size. Should be a multiple of 4.")
}
// drawing a quad take 16 floats: (2 x,y + 2 u,v) * 4 indices
for i := 0; i < len(vbo); i += 16 {
fmt.Println("Quad")
at := i
fmt.Printf(
"(0,0) (%.2f,%.2f); (U,V) (%f,%f) -> (%f,%f)\n",
vbo[at], vbo[at+1], vbo[at+2], vbo[at+3], vbo[at+2]*w, vbo[at+3]*h,
)
at += 4
fmt.Printf(
"(1,0) (%.2f,%.2f); (U,V) (%f,%f) -> (%f,%f)\n",
vbo[at], vbo[at+1], vbo[at+2], vbo[at+3], vbo[at+2]*w, vbo[at+3]*h,
)
at += 4
fmt.Printf(
"(1,1) (%.2f,%.2f); (U,V) (%f,%f) -> (%f,%f)\n",
vbo[at], vbo[at+1], vbo[at+2], vbo[at+3], vbo[at+2]*w, vbo[at+3]*h,
)
at += 4
fmt.Printf(
"(0,1) (%.2f,%.2f); (U,V) (%f,%f) -> (%f,%f)\n",
vbo[at], vbo[at+1], vbo[at+2], vbo[at+3], vbo[at+2]*w, vbo[at+3]*h,
)
}
}