func Uniform4f(dst Uniform, v0, v1, v2, v3 float32) { defer func() { errstr := errDrain() log.Printf("gl.Uniform4f(%v, %v, %v, %v, %v) %v", dst, v0, v1, v2, v3, errstr) }() C.glUniform4f(dst.c(), C.GLfloat(v0), C.GLfloat(v1), C.GLfloat(v2), C.GLfloat(v3)) }
func Uniform2f( location int32, x float32, y float32) { C.glUniform2f( C.GLint(location), C.GLfloat(x), C.GLfloat(y)) }
//void glMap1f (GLenum target, float32 u1, float32 u2, int stride, int order, const float32 *points) func Map1f(target GLenum, u1 float32, u2 float32, stride int, order int, points []float32) { if len(points) == 0 { panic("Invalid points size") } C.glMap1f(C.GLenum(target), C.GLfloat(u1), C.GLfloat(u2), C.GLint(stride), C.GLint(order), (*C.GLfloat)(&points[0])) }
func VertexAttrib2f( indx uint32, x float32, y float32) { C.glVertexAttrib2f( C.GLuint(indx), C.GLfloat(x), C.GLfloat(y)) }
func PolygonOffset(factor, units float32) { defer func() { errstr := errDrain() log.Printf("gl.PolygonOffset(%v, %v) %v", factor, units, errstr) }() C.glPolygonOffset(C.GLfloat(factor), C.GLfloat(units)) }
func VertexAttrib4f(dst Attrib, x, y, z, w float32) { defer func() { errstr := errDrain() log.Printf("gl.VertexAttrib4f(%v, %v, %v, %v, %v) %v", dst, x, y, z, w, errstr) }() C.glVertexAttrib4f(dst.c(), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w)) }
//void glMap2f (GLenum target, float32 u1, float32 u2, int ustride, int uorder, float32 v1, float32 v2, int vstride, int vorder, const float32 *points) func Map2f(target GLenum, u1 float32, u2 float32, ustride int, uorder int, v1 float32, v2 float32, vstride int, vorder int, points []float32) { if len(points) == 0 { panic("Invalid points size") } C.glMap2f(C.GLenum(target), C.GLfloat(u1), C.GLfloat(u2), C.GLint(ustride), C.GLint(uorder), C.GLfloat(v1), C.GLfloat(v2), C.GLint(vstride), C.GLint(vorder), (*C.GLfloat)(&points[0])) }
func Uniform4f( location int32, x float32, y float32, z float32, w float32) { C.glUniform4f( C.GLint(location), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w)) }
func VertexAttrib4f( indx uint32, x float32, y float32, z float32, w float32) { C.glVertexAttrib4f( C.GLuint(indx), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w)) }
func (game *game) drawFrame() { time += .05 color := (C.GLclampf(math.Sin(time)) + 1) * .5 C.glUniform2f(C.GLint(game.offsetUni), C.GLfloat(game.offsetX), C.GLfloat(game.offsetY)) C.glUniform3f(C.GLint(game.colorUni), 1.0, C.GLfloat(color), 0) C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT) C.glUseProgram(game.prog) C.glDrawArrays(C.GL_TRIANGLES, 0, 3) }
func ActualizeLight(n uint) { // n < MaxL // var L [4]float64 L[0], L[1], L[2] = lightSource[n].Coord3() var l [4]C.GLfloat for i := 0; i < 3; i++ { l[i] = C.GLfloat(L[i]) } l[3] = C.GLfloat(1.0) C.glLightfv(C.GL_LIGHT0+C.GLenum(n), C.GL_POSITION, &l[0]) C.glLightfv(C.GL_LIGHT0+C.GLenum(n), C.GL_AMBIENT, &aa[n][0]) C.glLightfv(C.GL_LIGHT0+C.GLenum(n), C.GL_DIFFUSE, &dd[n][0]) C.glEnable(C.GL_LIGHT0 + C.GLenum(n)) }
// TexParameter sets texture parameters. func TexParameter(targ TextureTarget, parm TexParam, val interface{}) { switch v := val.(type) { case float32: C.glTexParameterf(C.GLenum(targ), C.GLenum(parm), C.GLfloat(v)) case float64: C.glTexParameterf(C.GLenum(targ), C.GLenum(parm), C.GLfloat(v)) case int32: C.glTexParameteri(C.GLenum(targ), C.GLenum(parm), C.GLint(v)) case int: C.glTexParameteri(C.GLenum(targ), C.GLenum(parm), C.GLint(v)) default: panic("TexParameter requires either float32, float64, int32, or int") } }
func TexParameterf( target Enum, pname Enum, param float32) { C.glTexParameterf( C.GLenum(target), C.GLenum(pname), C.GLfloat(param)) }
func VertexAttrib1f(dst Attrib, x float32) { defer func() { errstr := errDrain() log.Printf("gl.VertexAttrib1f(%v, %v) %v", dst, x, errstr) }() C.glVertexAttrib1f(dst.c(), C.GLfloat(x)) }
func LineWidth(width float32) { defer func() { errstr := errDrain() log.Printf("gl.LineWidth(%v) %v", width, errstr) }() C.glLineWidth(C.GLfloat(width)) }
func Uniform1f(dst Uniform, v float32) { defer func() { errstr := errDrain() log.Printf("gl.Uniform1f(%v, %v) %v", dst, v, errstr) }() C.glUniform1f(dst.c(), C.GLfloat(v)) }
func TexParameterf(target, pname Enum, param float32) { defer func() { errstr := errDrain() log.Printf("gl.TexParameterf(%v, %v, %v) %v", target, pname, param, errstr) }() C.glTexParameterf(target.c(), pname.c(), C.GLfloat(param)) }
func SampleCoverage(value float32, invert bool) { b := C.GLboolean(C.GL_FALSE) if invert { b = C.GLboolean(C.GL_TRUE) } C.glSampleCoverage(C.GLfloat(value), C.GLboolean(b)) }
// Uniform specifies the value of a uniform variable for the current program object. func (u Uniform) Uniform(vls ...interface{}) { if len(vls) == 0 || len(vls) > 4 { panic("Uniform requires 1, 2, 3, or 4 values") } switch vls[0].(type) { case float32: switch len(vls) { case 1: C.glUniform1f(C.GLint(u), C.GLfloat(vls[0].(float32))) case 2: C.glUniform2f(C.GLint(u), C.GLfloat(vls[0].(float32)), C.GLfloat(vls[1].(float32))) case 3: C.glUniform3f(C.GLint(u), C.GLfloat(vls[0].(float32)), C.GLfloat(vls[1].(float32)), C.GLfloat(vls[2].(float32))) case 4: C.glUniform4f(C.GLint(u), C.GLfloat(vls[0].(float32)), C.GLfloat(vls[1].(float32)), C.GLfloat(vls[2].(float32)), C.GLfloat(vls[3].(float32))) } case int: switch len(vls) { case 1: C.glUniform1i(C.GLint(u), C.GLint(vls[0].(int))) case 2: C.glUniform2i(C.GLint(u), C.GLint(vls[0].(int)), C.GLint(vls[1].(int))) case 3: C.glUniform3i(C.GLint(u), C.GLint(vls[0].(int)), C.GLint(vls[1].(int)), C.GLint(vls[2].(int))) case 4: C.glUniform4i(C.GLint(u), C.GLint(vls[0].(int)), C.GLint(vls[1].(int)), C.GLint(vls[2].(int)), C.GLint(vls[3].(int))) } default: panic("Uniform only accepts int and float32 typed parameters") } }
func init() { // right[0], front[1], top[2] = 1.0, 1.0, 1.0 matrix[3][3] = 1. for l := 0; l < MaxL; l++ { lightSource[l] = vect.New() } w := 2.0 * math.Pi / float64(nLamp) sin[0], cos[0] = C.GLdouble(0.0), C.GLdouble(1.0) sin[nLamp], cos[nLamp] = sin[0], cos[0] for g := 1; g < nLamp; g++ { sin[g] = C.GLdouble(math.Sin(float64(g) * w)) cos[g] = C.GLdouble(math.Cos(float64(g) * w)) } sin[nLamp+1], sin[1] = cos[nLamp+1], cos[1] // C.glDepthFunc (C.GL_LESS) // default C.glEnable(C.GL_DEPTH_TEST) C.glShadeModel(C.GL_SMOOTH) for i := 0; i < 3; i++ { lmAmb[i] = C.GLfloat(0.2) } // default: 0.2 lmAmb[3] = C.GLfloat(1.0) // default: 1.0 C.glLightModelfv(C.GL_LIGHT_MODEL_AMBIENT, &lmAmb[0]) for i := 0; i < 3; i++ { mAmbi[i] = C.GLfloat(0.2) } // default: 0.2 mAmbi[3] = C.GLfloat(1.0) // default: 1.0 // C.glLightModelfv (C.GL_LIGHT_MODEL_TWO_SIDE, 1) C.glMaterialfv(C.GL_FRONT_AND_BACK, C.GL_AMBIENT_AND_DIFFUSE, &mAmbi[0]) for i := 0; i < 3; i++ { mDiff[i] = C.GLfloat(0.8) } // default: 0.8 mDiff[3] = C.GLfloat(1.0) // default: 1.0 w = 1. C.glClearDepth(C.GLclampd(w)) // C.glMaterialfv (C.GL_FRONT_AND_BACK, C.GL_DIFFUSE, mDiff) // C.glColorMaterial (C.GL_FRONT_AND_BACK, C.GL_DIFFUSE) // C.glColorMaterial (C.GL_FRONT, C.GL_AMBIENT) C.glColorMaterial(C.GL_FRONT_AND_BACK, C.GL_AMBIENT_AND_DIFFUSE) C.glEnable(C.GL_COLOR_MATERIAL) C.glEnable(C.GL_LIGHTING) initialize() }
// Pre: n < MaxL, 0 <= h[i] <= 1 für i = 0, 1. // Wenn Licht n schon eingeschaltet war, ist nichts verändert; andernfalls ist es // an der Position v in Farbe f mit der Ambienz h[0] und der Diffusität h[1] eingeschaltet. func InitLight(n uint, v, h *vect.Imp, c col.Colour) { // // if lightInitialized[n] { return } var a [4]float64 a[0], a[1], a[2] = h.Coord3() // Arbeitsdrumrum, weil die Punkte bisher nur eine Farbe transportieren, hier die diffuse. // In L wird die ambiente Farbe geliefert. for i := 0; i < 3; i++ { aa[n][i] = C.GLfloat(a[i]) } aa[n][3] = C.GLfloat(1.0) lightColour[n] = c d0, d1, d2 := col.Float(c) dd[n][0], dd[n][1], dd[n][2] = C.GLfloat(d0), C.GLfloat(d1), C.GLfloat(d2) dd[n][3] = C.GLfloat(1.0) lightSource[n].Copy(v) ActualizeLight(n) lightInitialized[n] = true }
func VertexAttrib3f(dst Attrib, x, y, z float32) { C.glVertexAttrib3f(dst.c(), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z)) }
func VertexAttrib4f(dst Attrib, x, y, z, w float32) { C.glVertexAttrib4f(dst.c(), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w)) }
func VertexAttrib1f(dst Attrib, x float32) { C.glVertexAttrib1f(dst.c(), C.GLfloat(x)) }
func VertexAttrib2f(dst Attrib, x, y float32) { C.glVertexAttrib2f(dst.c(), C.GLfloat(x), C.GLfloat(y)) }
func Uniform4f(dst Uniform, v0, v1, v2, v3 float32) { C.glUniform4f(dst.c(), C.GLfloat(v0), C.GLfloat(v1), C.GLfloat(v2), C.GLfloat(v3)) }
func Uniform3f(dst Uniform, v0, v1, v2 float32) { C.glUniform3f(dst.c(), C.GLfloat(v0), C.GLfloat(v1), C.GLfloat(v2)) }
func Uniform2f(dst Uniform, v0, v1 float32) { C.glUniform2f(dst.c(), C.GLfloat(v0), C.GLfloat(v1)) }
func Uniform1f(dst Uniform, v float32) { C.glUniform1f(dst.c(), C.GLfloat(v)) }
func TexParameterf(target, pname Enum, param float32) { C.glTexParameterf(target.c(), pname.c(), C.GLfloat(param)) }