forked from go-gl-legacy/glh
/
glh_test.go
138 lines (118 loc) · 3.04 KB
/
glh_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2012 The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package glh
import (
"testing"
"github.com/go-gl/gl"
"github.com/go-gl/testutils"
)
// Draw a test pattern
func TestWindowCoords(t *testing.T) {
gltest.OnTheMainThread(func() {
gltest.SetWindowSize(40, 40)
w, h := GetViewportWH()
With(WindowCoords{}, func() {
// So that we draw in the middle of the pixel
gl.Translated(0.5, 0.5, 0)
// Draw stripes
stride := 1
internal_n := 4
for b := 0; b < w/2-internal_n*stride; b += stride {
if b/stride%2 == 0 {
gl.Color4f(1, 1, 1, 1)
} else {
gl.Color4f(1, 0, 0, 1)
}
With(Primitive{gl.LINE_LOOP}, func() {
gl.Vertex2i(b, b)
gl.Vertex2i(w-b, b)
gl.Vertex2i(w-b, h-b)
gl.Vertex2i(b, h-b)
})
}
// Central white, green, blue checked pattern
gl.PointSize(2)
With(Primitive{gl.POINTS}, func() {
gl.Color4f(1, 1, 1, 1)
gl.Vertex2i(w/2-2, h/2-2)
gl.Vertex2i(w/2+2, h/2+2)
gl.Color4f(0, 1, 0, 1)
gl.Vertex2i(w/2+2, h/2-2)
gl.Vertex2i(w/2-2, h/2+2)
gl.Color4f(1, 1, 1, 1)
gl.Vertex2i(w/2, h/2)
})
// Blue horizontal line to show
With(Primitive{gl.LINE_LOOP}, func() {
gl.Color4f(0, 0, 1, 1)
gl.Vertex2i(0, h/2-4)
gl.Vertex2i(w, h/2-4)
gl.Vertex2i(w/2-4, 0)
gl.Vertex2i(w/2-4, h)
})
// Remove some pixels near the boundaries
gl.PointSize(1)
gl.Color4f(0, 0, 0, 1)
With(Primitive{gl.POINTS}, func() {
// Black dot in top left
gl.Vertex2i(0, 0)
// Off the top right (should not be visible)
gl.Vertex2i(w, 0)
// Bottom left pixel (should be visible as a black dot)
gl.Vertex2i(0, h-1)
})
})
}, func() {
CaptureToPng("TestWindowCoords.png")
})
}
// Draw a test pattern
func TestWindowCoordsA(t *testing.T) {
gltest.OnTheMainThread(func() {
gltest.SetWindowSize(40, 5)
w, h := GetViewportWH()
With(WindowCoords{}, func() {
// So that we draw in the middle of the pixel
gl.Translated(0.5, 0.5, 0)
gl.Color4f(1, 1, 1, 1)
With(Primitive{gl.POINTS}, func() {
for i := 0; i < w+1; i += 2 {
gl.Vertex2i(i, h/2)
}
})
})
}, func() {
CaptureToPng("TestWindowCoordsA.png")
})
}
// Check if the font can be found.
func TestMustInitText(t *testing.T) {
gltest.OnTheMainThread(func() {
err := func() (p interface{}) {
defer func() {
p = recover() // kill the panic here
}()
MustInitText()
return nil
}()
if err != nil {
t.Errorf("Unable to initialize the FontFile variable. Cause: %v", err)
}
var expectedFontFile = "invalid font file"
err = func() (p interface{}) {
defer func() {
p = recover()
}()
FontFile = expectedFontFile
MustInitText()
return nil
}()
if err != nil {
t.Errorf("When the FontFile variable is set, MustInitText should be a no-op, but got: %v", err)
}
if FontFile != expectedFontFile {
t.Errorf("Excpecting FontFile to be [%v] but got [%v]", expectedFontFile, FontFile)
}
}, func() {})
}