Ejemplo n.º 1
0
Archivo: gl.go Proyecto: james4k/gl
//void glMap1d (GLenum target, float64 u1, float64 u2, int stride, int order, const float64 *points)
func Map1d(target GLenum, u1 float64, u2 float64, stride int, order int, points []float64) {
	if len(points) == 0 {
		panic("Invalid points size")
	}
	C.glMap1d(C.GLenum(target), C.GLdouble(u1), C.GLdouble(u2),
		C.GLint(stride), C.GLint(order), (*C.GLdouble)(&points[0]))
}
Ejemplo n.º 2
0
func Perspective(fovy, aspect, zNear, zFar float64) {
	C.gluPerspective(
		C.GLdouble(fovy),
		C.GLdouble(aspect),
		C.GLdouble(zNear),
		C.GLdouble(zFar),
	)
}
Ejemplo n.º 3
0
// Project object coordinates to screen coordinates.
func Project(objx, objy, objz float64, model, proj []float64, view []int32) (x, y, z float64) {
	var wx, wy, wz C.GLdouble
	C.gluProject(
		C.GLdouble(objx), C.GLdouble(objy), C.GLdouble(objz), (*C.GLdouble)(&model[0]),
		(*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), &wx, &wy, &wz,
	)
	return float64(wx), float64(wy), float64(wz)
}
Ejemplo n.º 4
0
// Project screen coordinates to object coordinates.
func Unproject(wx, wy, wz float64, model, proj []float64, view []int32) (objx, objy, objz float64) {
	var ox, oy, oz C.GLdouble
	C.gluUnProject(
		C.GLdouble(wx), C.GLdouble(wy), C.GLdouble(wz), (*C.GLdouble)(&model[0]),
		(*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), &ox, &oy, &oz,
	)
	return float64(ox), float64(oy), float64(oz)
}
Ejemplo n.º 5
0
Archivo: gl.go Proyecto: james4k/gl
//void glMap2d (GLenum target, float64 u1, float64 u2, int ustride, int uorder, float64 v1, float64 v2, int vstride, int vorder, const float64 *points)
func Map2d(target GLenum, u1 float64, u2 float64, ustride int, uorder int, v1 float64, v2 float64, vstride int, vorder int, points []float64) {
	if len(points) == 0 {
		panic("Invalid points size")
	}
	C.glMap2d(C.GLenum(target), C.GLdouble(u1), C.GLdouble(u2), C.GLint(ustride),
		C.GLint(uorder), C.GLdouble(v1), C.GLdouble(v2), C.GLint(vstride),
		C.GLint(vorder), (*C.GLdouble)(&points[0]))
}
Ejemplo n.º 6
0
func LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float64) {
	C.gluLookAt(
		C.GLdouble(eyeX),
		C.GLdouble(eyeY),
		C.GLdouble(eyeZ),
		C.GLdouble(centerX),
		C.GLdouble(centerY),
		C.GLdouble(centerZ),
		C.GLdouble(upX),
		C.GLdouble(upY),
		C.GLdouble(upZ),
	)
}
Ejemplo n.º 7
0
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()
}
Ejemplo n.º 8
0
func lamp(n uint) {
	//
	if !lightInitialized[n] {
		return
	}
	xx, yy, zz := lightSource[n].Coord3()
	x, y, z := C.GLdouble(xx), C.GLdouble(yy), C.GLdouble(zz)
	r := C.GLdouble(0.1)
	C.glBegin(TRIANGLE_FAN)
	C.glColor3ub(C.GLubyte(lightColour[n].R), C.GLubyte(lightColour[n].G), C.GLubyte(lightColour[n].B))
	C.glNormal3d(C.GLdouble(0.0), C.GLdouble(0.0), C.GLdouble(-1.0))
	C.glVertex3d(C.GLdouble(x), C.GLdouble(y), C.GLdouble(z+r))
	r0 := r * sin[1]
	z0 := z + r*cos[1]
	for l := 0; l <= nLamp; l++ {
		C.glNormal3d(-sin[1]*cos[l], -sin[1]*sin[l], -cos[1])
		C.glVertex3d(x+r0*cos[l], y+r0*sin[l], z0)
	}
	C.glEnd()
	C.glBegin(QUAD_STRIP)
	var r1, z1 C.GLdouble
	for b := 1; b <= nLamp/2-2; b++ {
		r0, z0 = r*sin[b], z+r*cos[b]
		r1, z1 = r*sin[b+1], z+r*cos[b+1]
		for l := 0; l <= nLamp; l++ {
			C.glNormal3d(-sin[b+1]*cos[l], -sin[b+1]*sin[l], -cos[b+1])
			C.glVertex3d(x+r1*cos[l], y+r1*sin[l], z1)
			C.glNormal3d(-sin[b]*cos[l], -sin[b]*sin[l], -cos[b])
			C.glVertex3d(x+r0*cos[l], y+r0*sin[l], z0)
		}
	}
	C.glEnd()
	C.glBegin(TRIANGLE_FAN)
	C.glNormal3d(0., 0., 1.)
	C.glVertex3d(x, y, z-r)
	r0, z0 = r*sin[1], z-r*cos[1]
	b := nLamp/2 - 1
	for l := 0; l <= nLamp; l++ {
		C.glNormal3d(-sin[b]*cos[l], -sin[b]*sin[l], -cos[b])
		C.glVertex3d(x+r0*cos[l], y+r0*sin[l], z0)
	}
	C.glEnd()
}
Ejemplo n.º 9
0
func UnProject(winX, winY, winZ float64, model, proj *[16]float64, view *[4]int32) (float64, float64, float64) {
	var ox, oy, oz C.GLdouble

	m := (*C.GLdouble)(unsafe.Pointer(model))
	p := (*C.GLdouble)(unsafe.Pointer(proj))
	v := (*C.GLint)(unsafe.Pointer(view))

	C.gluUnProject(
		C.GLdouble(winX),
		C.GLdouble(winY),
		C.GLdouble(winZ),
		m,
		p,
		v,
		&ox,
		&oy,
		&oz,
	)

	return float64(ox), float64(oy), float64(oz)
}
Ejemplo n.º 10
0
func Init(fern float64) { // called by points.Start ()
	//
	const (
		D   = 2.0 // -fache Bildschirmbreite
		nah = C.GLdouble(0.2)
	)
	if !initialized {
		initialize()
	}
	C.glMatrixMode(C.GL_PROJECTION)
	C.glLoadIdentity()
	deg := D * math.Atan((0.5/D)/scr.Proportion())
	deg /= 0.9 // experimentelle Weitwinkelkorrektur
	var m [4][4]C.GLdouble
	m[1][1] = 1.0 / C.GLdouble(math.Tan(deg)) // Cot
	m[0][0] = m[1][1] / C.GLdouble(scr.Proportion())
	//  delta:= C.GLdouble(fern) - nah
	//  m[2][2] = - (C.GLdouble(fern) + nah) / delta
	//  m[2][3] = GLdouble(-1.0)
	//  m[3][2] = -2. * nah * C.GLdouble(fern) / delta
	m[2][2] = C.GLdouble(-1.0)
	m[2][3] = C.GLdouble(-1.0)
	m[3][2] = C.GLdouble(-1.0) * nah
	C.glMultMatrixd(&m[0][0])
	//  q:= C.GLdouble(0.75)
	//  GLFrustum (-1.0 * nah, 1.0 * nah, -q * nah, q * nah, 1.0 * nah, C.GLdouble(fern))
	C.glMatrixMode(C.GL_MODELVIEW)
}
Ejemplo n.º 11
0
func Write0() {
	//
	if !initialized {
		initialize()
	}
	if !scr.UnderX() {
		ker.Stop(pack, 1)
	}
	C.glMatrixMode(C.GL_MODELVIEW)
	C.glLoadIdentity()
	for i := 0; i < 3; i++ {
		matrix[i][0] = C.GLdouble(right[i])
		matrix[i][1] = C.GLdouble(top[i])
		matrix[i][2] = C.GLdouble(-front[i])
	}
	C.glMultMatrixd(&matrix[0][0])
	C.glTranslated(C.GLdouble(-eye[0]), C.GLdouble(-eye[1]), C.GLdouble(-eye[2]))
	C.glClear(C.GL_COLOR_BUFFER_BIT + C.GL_DEPTH_BUFFER_BIT)
	for n := uint(0); n < MaxL; n++ {
		if lightInitialized[n] {
			ActualizeLight(n)
		}
	}
	C.glBegin(POINTS)
	nn = 0
}
Ejemplo n.º 12
0
// Project screen coordinates to object coordinates.
func Unproject4(wx, wy, wz, clipw float64, model, proj []float64, view []int32, near, far float64) (objx, objy, objz, objw float64) {
	var ox, oy, oz, ow C.GLdouble
	C.gluUnProject4(
		C.GLdouble(wx), C.GLdouble(wy), C.GLdouble(wz), C.GLdouble(clipw),
		(*C.GLdouble)(&model[0]), (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]),
		C.GLdouble(near), C.GLdouble(far), &ox, &oy, &oz, &ow,
	)
	return float64(ox), float64(oy), float64(oz), float64(ow)
}
Ejemplo n.º 13
0
Archivo: texture.go Proyecto: Nvveen/gl
//void glTexGend (GLenum coord, GLenum pname, float64 param)
func TexGend(coord GLenum, pname GLenum, param float64) {
	C.glTexGend(C.GLenum(coord), C.GLenum(pname), C.GLdouble(param))
}
Ejemplo n.º 14
0
func Ortho2D(left, right, bottom, top float64) {
	C.gluOrtho2D(C.GLdouble(left), C.GLdouble(right), C.GLdouble(bottom), C.GLdouble(top))
}
Ejemplo n.º 15
0
func PickMatrix(x, y, delx, dely float64, viewport []int32) {
	C.gluPickMatrix(C.GLdouble(x), C.GLdouble(y), C.GLdouble(delx),
		C.GLdouble(dely), (*C.GLint)(&viewport[0]))
}
Ejemplo n.º 16
0
func WireCube(size gl.GLdouble) {
	C.glutWireCube(C.GLdouble(size))
}
Ejemplo n.º 17
0
func SolidCube(size gl.GLdouble) {
	C.glutSolidCube(C.GLdouble(size))
}
Ejemplo n.º 18
0
func WireTorus(innerRadius, outerRadius gl.GLdouble, nsides, rings gl.GLint) {
	C.glutWireTorus(C.GLdouble(innerRadius), C.GLdouble(outerRadius), C.GLint(nsides), C.GLint(rings))
}
Ejemplo n.º 19
0
// Set a property of the tesselator.
func (tess *Tesselator) Property(which gl.GLenum, data float64) {
	C.gluTessProperty(tess.tess, C.GLenum(which), C.GLdouble(data))
}
Ejemplo n.º 20
0
func Cylinder(q unsafe.Pointer, base, top, height float32, slices, stacks int) {
	C.gluCylinder((*[0]byte)(q), C.GLdouble(base), C.GLdouble(top), C.GLdouble(height), C.GLint(slices), C.GLint(stacks))
}
Ejemplo n.º 21
0
func Disk(q unsafe.Pointer, inner, outer float32, slices, loops int) {
	C.gluDisk((*[0]byte)(q), C.GLdouble(inner), C.GLdouble(outer), C.GLint(slices), C.GLint(loops))
}
Ejemplo n.º 22
0
// And, of course:
func SolidTeapot(size gl.GLdouble) {
	C.glutSolidTeapot(C.GLdouble(size))
}
Ejemplo n.º 23
0
Archivo: texture.go Proyecto: Nvveen/gl
//void glTexCoord3d (float64 s, float64 t, float64 r)
func TexCoord3d(s float64, t float64, r float64) {
	C.glTexCoord3d(C.GLdouble(s), C.GLdouble(t), C.GLdouble(r))
}
Ejemplo n.º 24
0
// Set the normal of the plane onto which points are projected onto before tesselation.
func (tess *Tesselator) Normal(valueX, valueY, valueZ float64) {
	cx := C.GLdouble(valueX)
	cy := C.GLdouble(valueY)
	cz := C.GLdouble(valueZ)
	C.gluTessNormal(tess.tess, cx, cy, cz)
}
Ejemplo n.º 25
0
Archivo: texture.go Proyecto: Nvveen/gl
//void glTexCoord1d (float64 s)
func TexCoord1d(s float64) {
	C.glTexCoord1d(C.GLdouble(s))
}
Ejemplo n.º 26
0
func WireCone(base, height gl.GLdouble, slices, stacks gl.GLint) {
	C.glutWireCone(C.GLdouble(base), C.GLdouble(height), C.GLint(slices), C.GLint(stacks))
}
Ejemplo n.º 27
0
Archivo: texture.go Proyecto: Nvveen/gl
//void glTexCoord2d (float64 s, float64 t)
func TexCoord2d(s float64, t float64) {
	C.glTexCoord2d(C.GLdouble(s), C.GLdouble(t))
}
Ejemplo n.º 28
0
func WireTeapot(size gl.GLdouble) {
	C.glutWireTeapot(C.GLdouble(size))
}
Ejemplo n.º 29
0
Archivo: texture.go Proyecto: Nvveen/gl
//void glTexCoord4d (float64 s, float64 t, float64 r, float64 q)
func TexCoord4d(s float64, t float64, r float64, q float64) {
	C.glTexCoord4d(C.GLdouble(s), C.GLdouble(t), C.GLdouble(r), C.GLdouble(q))
}
Ejemplo n.º 30
0
func Sphere(q unsafe.Pointer, radius float32, slices, stacks int) {
	C.gluSphere((*[0]byte)(q), C.GLdouble(radius), C.GLint(slices), C.GLint(stacks))
}