Ejemplo n.º 1
0
func (r *Receiver) Init(window *glfw.Window) {
	r.Window = window
	r.LoadConfiguration("gameconf.json")
	gtk.Bind(&r.Data)
	r.Shaders = gtk.NewShaderLibrary()
	r.Shaders.LoadProgram(ProgramScene, "scene.v.glsl", "scene.f.glsl")
	r.Shaders.BindProgramLocations(ProgramScene, &r.SceneLoc)
	gtk.PanicOnError()

	r.Data.Projection = glm.Ident4d()
	r.Data.Cameraview = glm.Ident4d()

	r.Data.Scene = gtk.EmptyModel("root")
	model, err := gtk.LoadSceneAsModel("drivetrain.dae")
	if err != nil {
		panic(err)
	}
	r.Data.Scene.AddChild(model)
	r.Data.Car, _ = model.FindModelWithName("Car")
	grid := gtk.EmptyModel("Grid")
	grid.AddGeometry(gtk.Grid(100))
	r.Data.Scene.AddChild(grid)

	r.Car = sim.NewCar()
	r.ResetKeyBindingDefaults()

	r.UIState = UIState{
		sim.Controls{},
		glm.Vec4d{0, 1, 0, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.QuatIdentd(),
		10,
	}
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
0
func (r *Receiver) Init(window *glfw.Window) {
	r.Window = window
	r.LoadConfiguration("gameconf.json")
	r.Invalid = true
	gtk.Bind(&r.Data)
	// var err error
	// err = gtk.LoadTexture(r.Data.Tex0, "tex4.png")
	// panicOnErr(err)
	// err = gtk.LoadTexture(r.Data.Tex1, "tex3.png")
	// panicOnErr(err)

	r.Shaders = gtk.NewShaderLibrary()
	r.Shaders.LoadProgram(PROGRAM_SCENE, "scene.v.glsl", "scene.f.glsl")
	r.Shaders.LoadProgram(PROGRAM_FILL, "fill.v.glsl", "fill.f.glsl")
	r.Shaders.BindProgramLocations(PROGRAM_SCENE, &r.SceneLoc)
	r.Shaders.BindProgramLocations(PROGRAM_FILL, &r.FillLoc)
	gtk.PanicOnError()

	r.Data.Projection = glm.Ident4d()
	r.Data.Cameraview = glm.Ident4d()
	r.Data.Inception = glm.Ident4d()

	r.Data.Scene = gtk.EmptyModel("root")
	r.LoadScene("portal.dae")

	quadElements := gtk.MakeElements(portal.QuadElements)
	r.Data.Scene.AddGeometry(NewPlane("plane1", portal.Quad{
		glm.Vec4d{0, 0, 0, 1},
		glm.Vec4d{0, 1, 0, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.Vec4d{10, 10, 1, 0},
	},
		quadElements,
	))
	r.Data.Fill = NewPlane("plane1", portal.Quad{
		glm.Vec4d{0, 0, 0, 1},
		glm.Vec4d{0, 0, 1, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.Vec4d{1, 1, 1, 0},
	},
		quadElements,
	)

	// r.Portals = append(r.Portals, CreatePortals()...)
	r.Data.Portal = gtk.EmptyModel("portals")
	for i, p := range r.Portals {
		r.Data.Portal.AddGeometry(NewPlane(fmt.Sprintf("portal_%d", i), p.EventHorizon, quadElements))
	}
	r.Player = Player{
		glm.Vec4d{0, 1, 0, 1},
		glm.Vec4d{0, 0, 0, 0},
		glm.Vec4d{0, 1, 0, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.QuatIdentd(),
		glm.QuatIdentd(),
	}
}
Ejemplo n.º 4
0
func (r *Receiver) Draw(window *glfw.Window) {
	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(ProgramScene)
	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))
	gtk.PanicOnError()
	gtk.DrawModel(glm.Ident4d(), r.Data.Scene, r.SceneLoc.Worldview, r.SceneLoc.Position, r.Data.Vao)
	// p := r.Data.Scene.Children[0].Transform.Mul4x1(r.Car.Center)
	// m := glm.Translate3Dd(math.Ceil(p[0]/5)*5,0,math.Ceil(p[2]/5)*5)
	// gtk.DrawModel(m, r.Data.Scene.Children[1], r.SceneLoc.Worldview, r.SceneLoc.Position, r.Data.Vao)
}
Ejemplo n.º 5
0
func (r *Receiver) DrawGeometry(geo *gtk.Geometry, vertexAttribute gl.AttributeLocation, lines bool) {
	gl.BindBuffer(gl.ARRAY_BUFFER, geo.VertexBuffer)
	gl.BindVertexArray(r.Data.Vao)
	gl.VertexAttribPointer(vertexAttribute, 3, gl.FLOAT, gl.FALSE, 12, nil)
	gl.EnableVertexAttribArray(vertexAttribute)

	for _, elem := range geo.Elements {
		if lines == (elem.DrawType == gl.LINES) {
			gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, elem.Buffer)
			gl.DrawElements(elem.DrawType, gl.Sizei(elem.Count), gl.UNSIGNED_SHORT, nil)
			gtk.PanicOnError()
		}
	}
	gl.DisableVertexAttribArray(vertexAttribute)
}