@@ -23,6 +23,8 @@ struct Vertex {
23
23
var TexCoord : ( Float , Float )
24
24
}
25
25
26
+ let TEX_COORD_MAX : Float = 1.0
27
+
26
28
class OpenGLView : UIView {
27
29
var _context : EAGLContext ?
28
30
var _colorRenderBuffer = GLuint ( )
@@ -41,35 +43,57 @@ class OpenGLView: UIView {
41
43
42
44
43
45
var _vertices = [
44
- Vertex ( Position: ( 1 , - 1 , 0 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( 1 , 0 ) ) ,
45
- Vertex ( Position: ( 1 , 1 , 0 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( 1 , 1 ) ) ,
46
- Vertex ( Position: ( - 1 , 1 , 0 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( 0 , 1 ) ) ,
47
- Vertex ( Position: ( - 1 , - 1 , 0 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
48
- Vertex ( Position: ( 1 , - 1 , - 1 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( 1 , 0 ) ) ,
49
- Vertex ( Position: ( 1 , 1 , - 1 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( 1 , 1 ) ) ,
50
- Vertex ( Position: ( - 1 , 1 , - 1 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( 0 , 1 ) ) ,
51
- Vertex ( Position: ( - 1 , - 1 , - 1 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( 0 , 0 ) )
46
+ // Front
47
+ Vertex ( Position: ( 1 , - 1 , 0 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, 0 ) ) ,
48
+ Vertex ( Position: ( 1 , 1 , 0 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, TEX_COORD_MAX) ) ,
49
+ Vertex ( Position: ( - 1 , 1 , 0 ) , Color: ( 0 , 0 , 1 , 1 ) , TexCoord: ( 0 , TEX_COORD_MAX) ) ,
50
+ Vertex ( Position: ( - 1 , - 1 , 0 ) , Color: ( 0 , 0 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
51
+ // Back
52
+ Vertex ( Position: ( 1 , 1 , - 2 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, 0 ) ) ,
53
+ Vertex ( Position: ( - 1 , - 1 , - 2 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, TEX_COORD_MAX) ) ,
54
+ Vertex ( Position: ( 1 , - 1 , - 2 ) , Color: ( 0 , 0 , 1 , 1 ) , TexCoord: ( 0 , TEX_COORD_MAX) ) ,
55
+ Vertex ( Position: ( - 1 , 1 , - 2 ) , Color: ( 0 , 0 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
56
+ // Left
57
+ Vertex ( Position: ( - 1 , - 1 , 0 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, 0 ) ) ,
58
+ Vertex ( Position: ( - 1 , 1 , 0 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, TEX_COORD_MAX) ) ,
59
+ Vertex ( Position: ( - 1 , 1 , - 2 ) , Color: ( 0 , 0 , 1 , 1 ) , TexCoord: ( 0 , TEX_COORD_MAX) ) ,
60
+ Vertex ( Position: ( - 1 , - 1 , - 2 ) , Color: ( 0 , 0 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
61
+ // Right
62
+ Vertex ( Position: ( 1 , - 1 , - 2 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, 0 ) ) ,
63
+ Vertex ( Position: ( 1 , 1 , - 2 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, TEX_COORD_MAX) ) ,
64
+ Vertex ( Position: ( 1 , 1 , 0 ) , Color: ( 0 , 0 , 1 , 1 ) , TexCoord: ( 0 , TEX_COORD_MAX) ) ,
65
+ Vertex ( Position: ( 1 , - 1 , 0 ) , Color: ( 0 , 0 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
66
+ // Top
67
+ Vertex ( Position: ( 1 , 1 , 0 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, 0 ) ) ,
68
+ Vertex ( Position: ( 1 , 1 , - 2 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, TEX_COORD_MAX) ) ,
69
+ Vertex ( Position: ( - 1 , 1 , - 2 ) , Color: ( 0 , 0 , 1 , 1 ) , TexCoord: ( 0 , TEX_COORD_MAX) ) ,
70
+ Vertex ( Position: ( - 1 , 1 , 0 ) , Color: ( 0 , 0 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
71
+ // Bottom
72
+ Vertex ( Position: ( 1 , - 1 , - 2 ) , Color: ( 1 , 0 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, 0 ) ) ,
73
+ Vertex ( Position: ( 1 , - 1 , 0 ) , Color: ( 0 , 1 , 0 , 1 ) , TexCoord: ( TEX_COORD_MAX, TEX_COORD_MAX) ) ,
74
+ Vertex ( Position: ( - 1 , - 1 , 0 ) , Color: ( 0 , 0 , 1 , 1 ) , TexCoord: ( 0 , TEX_COORD_MAX) ) ,
75
+ Vertex ( Position: ( - 1 , - 1 , - 2 ) , Color: ( 0 , 0 , 0 , 1 ) , TexCoord: ( 0 , 0 ) ) ,
52
76
]
53
77
54
78
var _indices : [ GLubyte ] = [
55
79
// Front
56
80
0 , 1 , 2 ,
57
81
2 , 3 , 0 ,
58
82
// Back
59
- 4 , 6 , 5 ,
60
- 4 , 7 , 6 ,
83
+ 4 , 5 , 6 ,
84
+ 4 , 5 , 7 ,
61
85
// Left
62
- 2 , 7 , 3 ,
63
- 7 , 6 , 2 ,
86
+ 8 , 9 , 10 ,
87
+ 10 , 11 , 8 ,
64
88
// Right
65
- 0 , 4 , 1 ,
66
- 4 , 1 , 5 ,
89
+ 12 , 13 , 14 ,
90
+ 14 , 15 , 12 ,
67
91
// Top
68
- 6 , 2 , 1 ,
69
- 1 , 6 , 5 ,
92
+ 16 , 17 , 18 ,
93
+ 18 , 19 , 16 ,
70
94
// Bottom
71
- 0 , 3 , 7 ,
72
- 0 , 7 , 4
95
+ 20 , 21 , 22 ,
96
+ 22 , 23 , 20
73
97
]
74
98
75
99
override init ( frame: CGRect ) {
0 commit comments