// SetActive will set current camera as the render camera func (cam *Camera) SetActive() { state.activeCam = cam if shader := shader.GetActive(); shader != nil { gl.UniformMatrix4fv(shader.Projection, 1, false, &cam.projection[0]) gl.UniformMatrix4fv(shader.Camera, 1, false, &cam.loc[0]) } }
// Draw will draw the billvboard in the x,y and z func (billboard *Billboard) Draw(x float32, y float32, z float32) { model := mgl32.Translate3D(x, y, z) if shader := shader.GetActive(); shader != nil { gl.UniformMatrix4fv(shader.Model, 1, false, &model[0]) } gl.BindVertexArray(billboard.vao) gl.ActiveTexture(gl.TEXTURE0) gl.BindTexture(gl.TEXTURE_2D, billboard.image) gl.DrawArrays(gl.TRIANGLES, 0, 1*2*3) }
// DrawFrame will draw the sprite in the x,y and z with the specified frame from a spritesheet func (sprite *Sprite) DrawFrame(x float32, y float32, z float32, scale float32, frame int) { model := mgl32.Translate3D(x, y, z) model = model.Mul4(mgl32.Scale3D(scale, scale, 1)) // remember this is in radians! // model = model.Mul4(mgl32.HomogRotate3D(mgl32.DegToRad(90), mgl32.Vec3{0, 0, 1})) if shader := shader.GetActive(); shader != nil { gl.UniformMatrix4fv(shader.Model, 1, false, &model[0]) } gl.BindVertexArray(sprite.vao) sprite.image.Bind() gl.DrawArrays(gl.TRIANGLES, int32(frame*6), 6) }