Ejemplo n.º 1
0
func NewFloor(shader loader.Shader, reflected ...Drawable) Drawable {
	glctx := shader.Context()
	floor := NewStaticShape(glctx)
	floor.vertices = floorVertices
	floor.normals = floorNormals
	floor.Buffer()
	flipped := mgl.Scale3D(1, -1, 1)
	return &Floor{
		Node: Node{
			Shape:     floor,
			transform: &flipped,
			shader:    shader,
		},
		reflected: reflected,
	}
}
Ejemplo n.º 2
0
func NewSkybox(shader loader.Shader, texture gl.Texture) Drawable {
	glctx := shader.Context()
	skyboxShape := NewStaticShape(glctx)
	skyboxShape.vertices = skyboxVertices
	skyboxShape.indices = skyboxIndices
	skyboxShape.Buffer()
	skyboxShape.Texture = texture

	skybox := &Skybox{
		Node: Node{
			Shape:  skyboxShape,
			shader: shader,
		},
	}

	return skybox
}
Ejemplo n.º 3
0
func (ctx *FrameContext) DrawContext(shader loader.Shader) DrawContext {
	r := DrawContext{
		GL:     ctx.GL,
		Camera: ctx.Camera,
		Shader: shader,
	}
	if ctx.activeShader != shader {
		shader.Use()
		ctx.activeShader = shader
	}
	if ctx.shaderCache == nil {
		ctx.shaderCache = map[loader.Shader]struct{}{shader: struct{}{}}
		ctx.bindShader(shader)
	} else if _, ok := ctx.shaderCache[shader]; !ok {
		ctx.bindShader(shader)
	}
	return r
}
Ejemplo n.º 4
0
func (ctx *FrameContext) bindShader(shader loader.Shader) {
	cam, glctx := ctx.Camera, ctx.GL
	projection, view, position := cam.Projection(), cam.View(), cam.Position()

	glctx.UniformMatrix4fv(shader.Uniform("cameraPos"), position[:])
	glctx.UniformMatrix4fv(shader.Uniform("view"), view[:])
	glctx.UniformMatrix4fv(shader.Uniform("projection"), projection[:])
}