Beispiel #1
0
func (r *Receiver) Draw(window *glfw.Window) {
	// fmt.Println("render", r.SimulationTime.Elapsed)
	bg := gtk.SoftBlack
	gl.ClearColor(bg[0], bg[1], bg[2], bg[3])
	gl.Enable(gl.DEPTH_TEST)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

	r.Shaders.UseProgram(PROGRAM_FILL)
	gl.Uniform4fv(r.FillLoc.Color, 1, &gtk.SkyBlue[0])
	gl.Uniform1f(r.FillLoc.Depth, gl.Float(r.Constants.PlayerViewFar))
	r.Shaders.UseProgram(PROGRAM_SCENE)
	gl.Uniform1f(r.SceneLoc.ElapsedSeconds, gl.Float(r.SimulationTime.Elapsed))
	gl.Uniform1f(r.SceneLoc.Glow, 0)
	gl.UniformMatrix4fv(r.SceneLoc.Projection, 1, gl.FALSE, gtk.MatArray(r.Data.Projection))
	gl.UniformMatrix4fv(r.SceneLoc.Cameraview, 1, gl.FALSE, gtk.MatArray(r.Data.Cameraview))
	gl.UniformMatrix4fv(r.SceneLoc.Inception, 1, gl.FALSE, gtk.MatArray(r.Data.Inception))
	mv := glm.Ident4d()
	gl.UniformMatrix4fv(r.SceneLoc.Portalview, 1, gl.FALSE, gtk.MatArray(mv))
	gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv))
	// gtk.AttachTexture(r.SceneLoc.Tex0, gl.TEXTURE0, gl.TEXTURE_2D, r.Data.Tex0)
	// gtk.AttachTexture(r.SceneLoc.Tex1, gl.TEXTURE1, gl.TEXTURE_2D, r.Data.Tex1)
	gtk.PanicOnError()

	r.DrawPortalScene(mv, 0, 1)
	r.Invalid = false
}
Beispiel #2
0
func MatArray(d glm.Mat4d) *gl.Float {
	n := len(d)
	f := make([]gl.Float, n)
	for i := 0; i < n; i++ {
		f[i] = gl.Float(d[i])
	}
	return &f[0]
}
Beispiel #3
0
func ArrayPtr(data interface{}) (gl.Pointer, gl.Sizeiptr) {
	var size gl.Sizeiptr
	var ptr gl.Pointer
	switch data := data.(type) {
	case []float64:
		duplicate := make([]gl.Float, len(data))
		for i, v := range data {
			duplicate[i] = gl.Float(v)
		}
		ptr, size = ArrayPtr(duplicate)
	case []float32:
		if len(data) == 0 {
			size = 0
			ptr = gl.Pointer(nil)
		} else {
			var v float32
			size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v)))
			ptr = gl.Pointer(&data[0])
		}
	case []gl.Float:
		if len(data) == 0 {
			size = 0
			ptr = gl.Pointer(nil)
		} else {
			var v gl.Float
			size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v)))
			ptr = gl.Pointer(&data[0])
		}
	case []int16:
		if len(data) == 0 {
			size = 0
			ptr = gl.Pointer(nil)
		} else {
			var v int16
			size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v)))
			ptr = gl.Pointer(&data[0])
		}
	case []gl.Ushort:
		if len(data) == 0 {
			size = 0
			ptr = gl.Pointer(nil)
		} else {
			var v gl.Ushort
			size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v)))
			ptr = gl.Pointer(&data[0])
		}
	case []int:
		duplicate := make([]gl.Ushort, len(data))
		for i, v := range data {
			duplicate[i] = gl.Ushort(v)
		}
		ptr, size = ArrayPtr(duplicate)
	case []gl.Int:
		if len(data) == 0 {
			size = 0
			ptr = gl.Pointer(nil)
		} else {
			var v gl.Int
			size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v)))
			ptr = gl.Pointer(&data[0])
		}
	default:
		panic(fmt.Sprintln("unknown data type:", reflect.TypeOf(data)))
	}
	return ptr, size
}