ebiten/graphics.go

93 lines
2.4 KiB
Go
Raw Normal View History

2014-12-09 15:16:04 +01:00
/*
Copyright 2014 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2014-12-09 14:09:22 +01:00
package ebiten
2013-12-02 13:45:10 +01:00
import (
"github.com/hajimehoshi/ebiten/internal/opengl"
"image/color"
)
2014-12-07 17:07:39 +01:00
// A Rect represents a rectangle.
2014-05-02 17:06:20 +02:00
type Rect struct {
2014-12-18 12:48:36 +01:00
X float64
Y float64
Width float64
Height float64
2014-05-02 17:06:20 +02:00
}
2014-12-07 17:07:39 +01:00
// A TexturePart represents a part of a texture.
2014-05-02 17:06:20 +02:00
type TexturePart struct {
2014-12-18 12:04:40 +01:00
Dst Rect
Src Rect
2014-05-02 17:06:20 +02:00
}
// DrawWholeTexture draws the whole texture.
func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
w, h := texture.Size()
2014-05-03 06:58:18 +02:00
parts := []TexturePart{
2014-12-18 12:48:36 +01:00
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
2014-05-03 06:58:18 +02:00
}
return g.DrawTexture(texture, parts, geo, color)
2014-05-03 06:58:18 +02:00
}
2014-12-14 14:05:44 +01:00
// A GraphicsContext is the interface that means a context of rendering.
2014-12-09 14:09:22 +01:00
type GraphicsContext interface {
2014-12-14 13:38:54 +01:00
Clear() error
Fill(clr color.Color) error
DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error
// TODO: ScreenRenderTarget() Drawer
PushRenderTarget(id *RenderTarget)
PopRenderTarget()
2013-12-02 13:45:10 +01:00
}
// Filter represents the type of filter to be used when a texture is maginified or minified.
type Filter int
2014-12-14 14:05:44 +01:00
// Filters
const (
FilterNearest Filter = iota
FilterLinear
)
// Texture represents a texture.
2014-12-17 13:49:28 +01:00
type Texture struct {
2014-12-17 14:12:32 +01:00
glTexture *opengl.Texture
2014-12-17 13:49:28 +01:00
}
// Size returns the size of the texture.
func (t *Texture) Size() (width int, height int) {
return t.glTexture.Width(), t.glTexture.Height()
}
// RenderTarget represents a render target.
// A render target is essentially same as a texture, but it is assumed that the
// all alpha values of a render target is maximum.
2014-12-17 13:49:28 +01:00
type RenderTarget struct {
2014-12-17 14:24:30 +01:00
glRenderTarget *opengl.RenderTarget
texture *Texture
2014-12-17 13:49:28 +01:00
}
// Texture returns the texture of the render target.
func (r *RenderTarget) Texture() *Texture {
return r.texture
}
// Size returns the size of the render target.
func (r *RenderTarget) Size() (width int, height int) {
return r.glRenderTarget.Width(), r.glRenderTarget.Height()
}