-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl.go
183 lines (148 loc) · 4.58 KB
/
gl.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package gogl3w
/*
#cgo darwin LDFLAGS: -framework OpenGL -lGL
#cgo windows LDFLAGS: -lopengl32
#cgo linux LDFLAGS: -lGL
#include <GL3/gl3w.h>
void (APIENTRYP ptrgoglClear)(GLbitfield mask);
void (APIENTRYP ptrgoglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
void (APIENTRYP ptrgoglBindVertexArray)(GLuint array);
void (APIENTRYP ptrgoglDeleteVertexArrays)(GLsizei n, const GLuint* arrays);
void (APIENTRYP ptrgoglGenVertexArrays)(GLsizei n, GLuint* arrays);
void (APIENTRYP ptrgoglBindBuffer)(GLenum target, GLuint buffer);
void (APIENTRYP ptrgoglDeleteBuffers)(GLsizei n, const GLuint* buffers);
void (APIENTRYP ptrgoglGenBuffers)(GLsizei n, GLuint* buffers);
void connectGLpointers(void) {
ptrgoglClear = glClear;
ptrgoglClearColor = glClearColor;
ptrgoglBindVertexArray = glBindVertexArray;
ptrgoglDeleteVertexArrays = glDeleteVertexArrays;
ptrgoglGenVertexArrays = glGenVertexArrays;
ptrgoglBindBuffer = glBindBuffer;
ptrgoglDeleteBuffers = glDeleteBuffers;
ptrgoglGenBuffers = glGenBuffers;
}
void goglClear(GLbitfield mask) {
glClear(mask);
}
void goglClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
(*ptrgoglClearColor)(red, green, blue, alpha);
}
void goglBindVertexArray(GLuint array) {
(*ptrgoglBindVertexArray)(array);
}
void goglDeleteVertexArrays(GLsizei n, GLuint* arrays) {
(*ptrgoglDeleteVertexArrays)(n, arrays);
}
void goglGenVertexArrays(GLsizei n, GLuint* arrays) {
(*ptrgoglGenVertexArrays)(n, arrays);
}
void goglBindBuffer(GLenum target, GLuint buffer) {
(*ptrgoglBindBuffer)(target, buffer);
}
void goglDeleteBuffers(GLsizei n, GLuint* buffers) {
(*ptrgoglDeleteBuffers)(n, buffers);
}
void goglGenBuffers(GLsizei n, GLuint* buffers) {
(*ptrgoglGenBuffers)(n, buffers);
}
*/
import "C"
import "unsafe"
import "runtime"
// import "reflect"
import "log"
type GLenum C.GLenum
type GLbitfield C.GLbitfield
type GLclampf C.GLclampf
type GLclampd C.GLclampd
type Pointer unsafe.Pointer
// those types are left for compatibility reasons
// type GLboolean C.GLboolean
// type GLbyte C.GLbyte
// type GLshort C.GLshort
// type GLint C.GLint
// type GLsizei C.GLsizei
// type GLubyte C.GLubyte
// type GLushort C.GLushort
// type GLuint C.GLuint
// type GLfloat C.GLfloat
// type GLdouble C.GLdouble
// helpers
func Init() {
log.Printf("Clear: %p", C.ptrgoglClear)
log.Printf("GenVAO: %p", C.ptrgoglGenVertexArrays)
initResult := C.gl3wInit()
log.Printf("Init result: %d", initResult)
C.connectGLpointers()
}
//void glBegin (GLenum mode)
func Begin(mode GLenum) {
}
//void glEnd (void)
func End() {
}
//void glClear (GLbitfield mask)
func Clear(mask GLbitfield) {
C.goglClear(C.GLbitfield(mask))
log.Println("Cleared!")
}
//void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
func ClearColor(red GLclampf, green GLclampf, blue GLclampf, alpha GLclampf) {
C.goglClearColor(C.GLclampf(red), C.GLclampf(green), C.GLclampf(blue), C.GLclampf(alpha))
log.Println("Colored!")
}
type Object C.GLuint
type Buffer Object
// // Create single buffer object
func GenBuffer() Buffer {
var b C.GLuint
C.goglGenBuffers(1, &b)
return Buffer(b)
}
// // Fill slice with new buffers
func GenBuffers(buffers []Buffer) {
C.goglGenBuffers(C.GLsizei(len(buffers)), (*C.GLuint)(&buffers[0]))
}
// // Delete buffer object
// func (buffer Buffer) Delete() {
// b := C.GLuint(buffer)
// C.glDeleteBuffers(1, &b)
// }
// // Delete all textures in slice
// func DeleteBuffers(buffers []Buffer) {
// C.glDeleteBuffers(C.GLsizei(len(buffers)), (*C.GLuint)(&buffers[0]))
// }
// // Bind this buffer as target
func (buffer Buffer) Bind(target GLenum) {
C.goglBindBuffer(C.GLenum(target), C.GLuint(buffer))
}
// // Bind this buff
// // Vertex Arrays
type VertexArray Object
func GenVertexArray() VertexArray {
var a C.GLuint
log.Printf("Clear: %p", C.ptrgoglClear)
log.Printf("GenVAO: %p", C.ptrgoglGenVertexArrays)
log.Printf("Address of A: %p", &a)
stackBuf := make([]byte, 0)
_ = runtime.Stack(stackBuf, true)
log.Printf("Stack-izzy: %v", stackBuf)
C.goglGenVertexArrays(1, &a)
log.Printf("Value of A: %p", a)
log.Println("eh??")
// C.goglGenVertexArrays((C.GLsizei)(n), (*C.GLuint)(arrays))
return VertexArray(a)
}
func GenVertexArrays(arrays []VertexArray) {
C.goglGenVertexArrays(C.GLsizei(len(arrays)), (*C.GLuint)(&arrays[0]))
}
// func (array VertexArray) Delete() {
// C.glDeleteVertexArrays(1, (*C.GLuint)(&array))
// }
// func DeleteVertexArrays(arrays []VertexArray) {
// C.glDeleteVertexArrays(C.GLsizei(len(arrays)), (*C.GLuint)(&arrays[0]))
// }
func (array VertexArray) Bind() {
C.goglBindVertexArray(C.GLuint(array))
}