Beispiel #1
0
func (shape *StaticShape) Draw(shader Shader, camera Camera) {
	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)

	if len(shape.normals) > 0 {
		gl.EnableVertexAttribArray(shader.Attrib("vertNormal"))
		gl.VertexAttribPointer(shader.Attrib("vertNormal"), normalDim, gl.FLOAT, false, stride, vertexDim*vecSize)
	}
	// TODO: texture

	if len(shape.indices) > 0 {
		gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, shape.IBO)
		gl.DrawElements(gl.TRIANGLES, len(shape.indices), gl.UNSIGNED_BYTE, 0)
	} else {
		gl.DrawArrays(gl.TRIANGLES, 0, shape.Len())
	}

	gl.DisableVertexAttribArray(shader.Attrib("vertCoord"))
	if len(shape.normals) > 0 {
		gl.DisableVertexAttribArray(shader.Attrib("vertNormal"))
	}
	// TODO: texture
}
Beispiel #2
0
func (shape *Skybox) Draw(camera Camera) {
	shader := shape.shader

	gl.DepthFunc(gl.LEQUAL)
	gl.DepthMask(false)

	projection, view := camera.Projection(), camera.View().Mat3().Mat4()
	gl.UniformMatrix4fv(shader.Uniform("projection"), projection[:])
	gl.UniformMatrix4fv(shader.Uniform("view"), view[:])

	gl.BindTexture(gl.TEXTURE_CUBE_MAP, shape.Texture)

	gl.BindBuffer(gl.ARRAY_BUFFER, shape.VBO)
	gl.EnableVertexAttribArray(shader.Attrib("vertCoord"))
	gl.VertexAttribPointer(shader.Attrib("vertCoord"), vertexDim, gl.FLOAT, false, shape.Stride(), 0)

	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, shape.IBO)
	gl.DrawElements(gl.TRIANGLES, len(shape.indices), gl.UNSIGNED_BYTE, 0)
	gl.DisableVertexAttribArray(shader.Attrib("vertCoord"))

	gl.DepthMask(true)
	gl.DepthFunc(gl.LESS)
}