Change Game.Draw to have graphics.Texture

This commit is contained in:
Hajime Hoshi 2013-06-21 01:56:24 +09:00
parent b430d385bf
commit 93565f79a9
3 changed files with 6 additions and 6 deletions

View File

@ -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

View File

@ -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()

View File

@ -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)