Esempio n. 1
0
File: glm.go Progetto: Niriel/daggor
func (self Vector3) GlFloats() [3]gl.GLfloat {
	return [3]gl.GLfloat{
		gl.GLfloat(self[0]),
		gl.GLfloat(self[1]),
		gl.GLfloat(self[2]),
	}
}
Esempio n. 2
0
File: glm.go Progetto: Niriel/daggor
func (self Vector4) GlFloats() [4]gl.GLfloat {
	return [4]gl.GLfloat{
		gl.GLfloat(self[0]),
		gl.GLfloat(self[1]),
		gl.GLfloat(self[2]),
		gl.GLfloat(self[3]),
	}
}
Esempio n. 3
0
func GetColor(cell int) (red, green, blue gl.GLfloat) {
	ccell := C.int(cell)

	red = gl.GLfloat(C.glutGetColor(ccell, RED))
	green = gl.GLfloat(C.glutGetColor(ccell, GREEN))
	blue = gl.GLfloat(C.glutGetColor(ccell, BLUE))

	return
}
Esempio n. 4
0
File: glm.go Progetto: Niriel/daggor
func (a Matrix4) GlFloats() [16]gl.GLfloat {
	var result [16]gl.GLfloat
	for i := 0; i < 16; i++ {
		result[i] = gl.GLfloat(a[i])
	}
	return result
}
Esempio n. 5
0
func (buffer *ModelMatInstances) attribPointers(atts []gl.AttribLocation) {
	const FLOATSIZE = unsafe.Sizeof(gl.GLfloat(0))
	const NB_COORDS = 4 // 4 floats per matrix row.
	const NB_ATTS = 4   // Matrix is 4 rows or 4 columns.
	const COORDS_SIZE = NB_COORDS * FLOATSIZE
	const COORDS_OFS = uintptr(0)
	const TOTAL_SIZE = int(COORDS_SIZE) * NB_ATTS
	for i := 0; i < NB_ATTS; i++ {
		// We pass each column of the matrix separately.
		// Because that's how OpenGL does matrix vertex attributes.
		att := atts[0] + gl.AttribLocation(i)
		offset := COORDS_OFS + uintptr(i)*COORDS_SIZE
		att.AttribPointer(NB_COORDS, gl.FLOAT, false, TOTAL_SIZE, offset)
		if err := CheckGlError(); err != nil {
			err.Description = "ModelMatInstances att.AttribPointer"
			panic(err)
		}
		// 1 here means that we switch to a new matrix every 1 instance.
		// This AttribDivisor call with a non-zero value is what makes the
		// attribute instanced.
		att.AttribDivisor(1)
		if err := CheckGlError(); err != nil {
			err.Description = "ModelMatInstances att.AttribDivisor"
			panic(err)
		}
		// Each column of the matrix must be enabled.
		att.EnableArray()
		if err := CheckGlError(); err != nil {
			err.Description = fmt.Sprintf("atts[%v].EnableArray()\n", att)
			panic(err)
		}
	}
}
Esempio n. 6
0
func (buffer *VerticesXyzNorUv) attribPointers(atts []gl.AttribLocation) {
	const FLOATSIZE = unsafe.Sizeof(gl.GLfloat(0))
	const NB_POS = 3 // px py and pz.
	const NB_NOR = 3 // nx ny and nz.
	const NB_UV = 2  // u and v.
	const POS_SIZE = NB_POS * FLOATSIZE
	const NOR_SIZE = NB_NOR * FLOATSIZE
	const UV_SIZE = NB_UV * FLOATSIZE
	const POS_OFS = uintptr(0)
	const NOR_OFS = uintptr(POS_SIZE)
	const UV_OFS = uintptr(POS_SIZE + NOR_SIZE)
	const TOTAL_SIZE = int(POS_SIZE + NOR_SIZE + UV_SIZE)
	atts[0].AttribPointer(NB_POS, gl.FLOAT, false, TOTAL_SIZE, POS_OFS)
	if err := CheckGlError(); err != nil {
		err.Description = "VerticesXyzNorUv atts[0].AttribPointer"
		panic(err)
	}
	atts[1].AttribPointer(NB_NOR, gl.FLOAT, false, TOTAL_SIZE, NOR_OFS)
	if err := CheckGlError(); err != nil {
		err.Description = "VerticesXyzNorUv atts[1].AttribPointer"
		panic(err)
	}
	atts[2].AttribPointer(NB_UV, gl.FLOAT, false, TOTAL_SIZE, UV_OFS)
	if err := CheckGlError(); err != nil {
		err.Description = "VerticesXyzNorUv atts[2].AttribPointer"
		panic(err)
	}
	for _, att := range atts {
		att.EnableArray()
		if err := CheckGlError(); err != nil {
			err.Description = fmt.Sprintf("atts[%v].EnableArray()\n", att)
			panic(err)
		}
	}
}
Esempio n. 7
0
func (buffer *VerticesXyzRgb) attribPointers(atts []gl.AttribLocation) {
	const FLOATSIZE = unsafe.Sizeof(gl.GLfloat(0))
	const NB_COORDS = 3 // x y and z.
	const NB_COLORS = 3 // r g and b.
	const COORDS_SIZE = NB_COORDS * FLOATSIZE
	const COLORS_SIZE = NB_COLORS * FLOATSIZE
	const COORDS_OFS = uintptr(0)
	const COLORS_OFS = uintptr(COORDS_SIZE)
	const TOTAL_SIZE = int(COORDS_SIZE + COLORS_SIZE)
	atts[0].AttribPointer(NB_COORDS, gl.FLOAT, false, TOTAL_SIZE, COORDS_OFS)
	if err := CheckGlError(); err != nil {
		err.Description = "VerticesXyzRgb atts[0].AttribPointer"
		panic(err)
	}
	atts[1].AttribPointer(NB_COLORS, gl.FLOAT, false, TOTAL_SIZE, COLORS_OFS)
	if err := CheckGlError(); err != nil {
		err.Description = "VerticesXyzRgb atts[1].AttribPointer"
		panic(err)
	}
	for _, att := range atts {
		att.EnableArray()
		if err := CheckGlError(); err != nil {
			err.Description = fmt.Sprintf("atts[%v].EnableArray()\n", att)
			panic(err)
		}
	}
}
Esempio n. 8
0
func MakeVertexXyzNor(pos, nor glm.Vector3) VertexXyzNor {
	px64, py64, pz64 := pos.Xyz()
	nx64, ny64, nz64 := nor.Xyz()
	return VertexXyzNor{
		Px: gl.GLfloat(px64),
		Py: gl.GLfloat(py64),
		Pz: gl.GLfloat(pz64),
		Nx: gl.GLfloat(nx64),
		Ny: gl.GLfloat(ny64),
		Nz: gl.GLfloat(nz64),
	}
}