Пример #1
0
func (scene *Floor) Draw(camera Camera) {
	shader, _ := scene.UseShader(nil)

	gl.Enable(gl.STENCIL_TEST)
	gl.StencilFunc(gl.ALWAYS, 1, 0xFF)
	gl.StencilOp(gl.KEEP, gl.KEEP, gl.REPLACE)
	gl.StencilMask(0xFF)
	gl.DepthMask(false)
	gl.Clear(gl.STENCIL_BUFFER_BIT)

	// Draw floor
	gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.1, 0.1, 0.1})
	scene.Shape.Draw(shader, camera)

	// Draw reflections
	gl.StencilFunc(gl.EQUAL, 1, 0xFF)
	gl.StencilMask(0x00)
	gl.DepthMask(true)

	view := camera.View()
	gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.3, 0.3, 0.3})
	for _, node := range scene.reflected {
		model := node.Transform(scene.transform)
		gl.UniformMatrix4fv(shader.Uniform("model"), model[:])

		normal := model.Mul4(view).Inv().Transpose()
		gl.UniformMatrix4fv(shader.Uniform("normalMatrix"), normal[:])

		node.Draw(camera)
	}

	gl.Disable(gl.STENCIL_TEST)
}
Пример #2
0
func (shape *arena) Draw(camera Camera) {
	shader := shape.shader
	gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.05, 0.0, 0.02})
	gl.Uniform3fv(shader.Uniform("lights[0].color"), []float32{0.2, 0.1, 0.1})
	gl.Uniform1f(shader.Uniform("lights[0].intensity"), 0.3)

	// TODO: Move this into a texture
	gl.Uniform1f(shader.Uniform("lights[1].intensity"), 25.0)
	gl.Uniform3fv(shader.Uniform("lights[1].position"), []float32{0, 20, 0})
	gl.Uniform3fv(shader.Uniform("lights[1].color"), []float32{0.05, 0.0, 0.1})

	shape.Node.Draw(camera)
}
Пример #3
0
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0.5, 0.8, 0.8, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	gl.Uniform3fv(e.shader.lightdir, []float32{0.5, 0.6, 0.7})

	m := mgl32.Perspective(1.3, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projectionmatrix, m[:])

	eye := mgl32.Vec3{0, 0, 0.2}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.viewmatrix, m[:])

	m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelmatrix, m[:])

	m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, -1, 0})
	gl.UniformMatrix4fv(e.shader.lightmatrix, m[:])

	coordsPerVertex := 3
	for _, obj := range e.shape.Objs {
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
		gl.EnableVertexAttribArray(e.shader.vertCoord)
		gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)

		texCoordsPerVertex := 2
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
		gl.EnableVertexAttribArray(e.shader.texcoord)
		gl.VertexAttribPointer(e.shader.texcoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)

		gl.BindBuffer(gl.ARRAY_BUFFER, obj.normal)
		gl.EnableVertexAttribArray(e.shader.normal)
		gl.VertexAttribPointer(e.shader.normal, 3, gl.FLOAT, false, 12, 0)

		gl.BindTexture(gl.TEXTURE_2D, obj.tex)

		gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)

		gl.DisableVertexAttribArray(e.shader.texcoord)
		gl.DisableVertexAttribArray(e.shader.normal)
		gl.DisableVertexAttribArray(e.shader.vertCoord)
	}

	debug.DrawFPS(c)
}
Пример #4
0
func (shape *Line) Draw(camera Camera) {
	shader := shape.shader

	// Set uniforms
	gl.Uniform1f(shader.Uniform("lights[0].intensity"), 2.0)
	gl.Uniform3fv(shader.Uniform("lights[0].position"), shape.position[:])
	gl.Uniform3fv(shader.Uniform("lights[0].color"), []float32{0.4, 0.2, 0.1})

	gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.1, 0.15, 0.4})
	//gl.Uniform3fv(shader.Uniform("material.diffuse"), []float32{0.8, 0.6, 0.6})
	//gl.Uniform3fv(shader.Uniform("material.specular"), []float32{1.0, 1.0, 1.0})
	//gl.Uniform1f(shader.Uniform("material.shininess"), 16.0)
	//gl.Uniform1f(shader.Uniform("material.refraction"), 1.0/1.52)

	gl.BindBuffer(gl.ARRAY_BUFFER, shape.VBO)
	stride := shape.Stride()

	gl.EnableVertexAttribArray(shader.Attrib("vertCoord"))
	gl.VertexAttribPointer(shader.Attrib("vertCoord"), vertexDim, gl.FLOAT, false, stride, 0)

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, shape.Len())
}