mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
Change Game.Draw to have graphics.Texture
This commit is contained in:
parent
b430d385bf
commit
93565f79a9
@ -9,7 +9,7 @@ import (
|
|||||||
type Game interface {
|
type Game interface {
|
||||||
Init(tf graphics.TextureFactory)
|
Init(tf graphics.TextureFactory)
|
||||||
Update()
|
Update()
|
||||||
Draw(g graphics.GraphicsContext, offscreen graphics.TextureID)
|
Draw(g graphics.GraphicsContext, offscreen graphics.Texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UI interface {
|
type UI interface {
|
||||||
@ -23,7 +23,7 @@ func OpenGLRun(game Game, ui UI) {
|
|||||||
ch := make(chan bool, 1)
|
ch := make(chan bool, 1)
|
||||||
device := opengl.NewDevice(
|
device := opengl.NewDevice(
|
||||||
ui.ScreenWidth(), ui.ScreenHeight(), ui.ScreenScale(),
|
ui.ScreenWidth(), ui.ScreenHeight(), ui.ScreenScale(),
|
||||||
func(g graphics.GraphicsContext, offscreen graphics.TextureID) {
|
func(g graphics.GraphicsContext, offscreen graphics.Texture) {
|
||||||
ticket := <-ch
|
ticket := <-ch
|
||||||
game.Draw(g, offscreen)
|
game.Draw(g, offscreen)
|
||||||
ch <- ticket
|
ch <- ticket
|
||||||
|
@ -115,7 +115,7 @@ func (game *DemoGame) Update() {
|
|||||||
game.x++
|
game.x++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *DemoGame) Draw(g graphics.GraphicsContext, offscreen graphics.TextureID) {
|
func (game *DemoGame) Draw(g graphics.GraphicsContext, offscreen graphics.Texture) {
|
||||||
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
||||||
|
|
||||||
geometryMatrix := matrix.IdentityGeometry()
|
geometryMatrix := matrix.IdentityGeometry()
|
||||||
|
@ -16,11 +16,11 @@ type Device struct {
|
|||||||
screenScale int
|
screenScale int
|
||||||
graphicsContext *GraphicsContext
|
graphicsContext *GraphicsContext
|
||||||
offscreenTexture graphics.Texture
|
offscreenTexture graphics.Texture
|
||||||
drawFunc func(graphics.GraphicsContext, graphics.TextureID)
|
drawFunc func(graphics.GraphicsContext, graphics.Texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(screenWidth, screenHeight, screenScale int,
|
func NewDevice(screenWidth, screenHeight, screenScale int,
|
||||||
drawFunc func(graphics.GraphicsContext, graphics.TextureID)) *Device {
|
drawFunc func(graphics.GraphicsContext, graphics.Texture)) *Device {
|
||||||
device := &Device{
|
device := &Device{
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
screenHeight: screenHeight,
|
screenHeight: screenHeight,
|
||||||
@ -40,7 +40,7 @@ func (device *Device) Update() {
|
|||||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
||||||
g.SetOffscreen(device.offscreenTexture.ID)
|
g.SetOffscreen(device.offscreenTexture.ID)
|
||||||
g.Clear()
|
g.Clear()
|
||||||
device.drawFunc(g, device.offscreenTexture.ID)
|
device.drawFunc(g, device.offscreenTexture)
|
||||||
g.flush()
|
g.flush()
|
||||||
|
|
||||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR)
|
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR)
|
||||||
|
Loading…
Reference in New Issue
Block a user