Change the signiture of GraphicsContext.DrawTexture

This commit is contained in:
Hajime Hoshi 2013-06-23 21:51:23 +09:00
parent 81a7d4c4fd
commit 92ac4b97ea
8 changed files with 27 additions and 13 deletions

View File

@ -6,6 +6,11 @@ import (
"time"
)
type TapInfo struct {
X int
Y int
}
type Game interface {
ScreenWidth() int
ScreenHeight() int
@ -20,7 +25,7 @@ type UI interface {
func OpenGLRun(game Game, ui UI, screenScale int) {
ch := make(chan bool, 1)
device := opengl.NewDevice(
graphicsDevice := opengl.NewDevice(
game.ScreenWidth(), game.ScreenHeight(), screenScale,
func(g graphics.GraphicsContext, offscreen graphics.Texture) {
ticket := <-ch
@ -39,7 +44,7 @@ func OpenGLRun(game Game, ui UI, screenScale int) {
}
}()
game.Init(device.TextureFactory())
game.Init(graphicsDevice.TextureFactory())
ch <- true
ui.Run(device)
ui.Run(graphicsDevice)
}

View File

@ -50,7 +50,7 @@ func (game *Rects) Draw(g graphics.GraphicsContext, offscreen graphics.Texture)
)
g.SetOffscreen(offscreen.ID)
g.DrawTexture(game.rectsTexture,
g.DrawTexture(game.rectsTexture.ID,
matrix.IdentityGeometry(),
matrix.IdentityColor())
}

View File

@ -59,7 +59,7 @@ func (game *Rotating) Draw(g graphics.GraphicsContext, offscreen graphics.Textur
centerY := float64(game.ScreenHeight()) / 2
geometryMatrix.Translate(centerX-tx/2, centerY-ty/2)
g.DrawTexture(game.ebitenTexture,
g.DrawTexture(game.ebitenTexture.ID,
geometryMatrix,
matrix.IdentityColor())
}

View File

@ -90,7 +90,7 @@ func (game *Sprites) Init(tf graphics.TextureFactory) {
panic(err)
}
game.sprites = []*Sprite{}
for i := 0; i < 1000; i++ {
for i := 0; i < 100; i++ {
sprite := newSprite(
game.ScreenWidth(),
game.ScreenHeight(),

View File

@ -6,10 +6,12 @@ package main
// #include <GLUT/glut.h>
//
// void display(void);
// void mouse(int button, int state, int x, int y);
// void idle(void);
//
// static void setGlutFuncs(void) {
// glutDisplayFunc(display);
// glutMouseFunc(mouse);
// glutIdleFunc(idle);
// }
//
@ -37,6 +39,11 @@ func display() {
C.glutSwapBuffers()
}
//export mouse
func mouse(button, state, x, y C.int) {
}
//export idle
func idle() {
C.glutPostRedisplay()

View File

@ -28,14 +28,14 @@ type GraphicsContext interface {
Clear()
Fill(color color.Color)
DrawRect(rect Rect, clr color.Color)
DrawTexture(texture Texture,
DrawTexture(textureID TextureID,
geometryMatrix matrix.Geometry,
colorMatrix matrix.Color)
DrawTextureParts(textureId TextureID,
DrawTextureParts(textureID TextureID,
locations []TexturePart,
geometryMatrix matrix.Geometry,
colorMatrix matrix.Color)
SetOffscreen(textureId TextureID)
SetOffscreen(textureID TextureID)
}
type TextureFactory interface {

View File

@ -55,7 +55,7 @@ func (device *Device) Update() {
{0, scale, 0},
},
}
g.DrawTexture(device.offscreenTexture,
g.DrawTexture(device.offscreenTexture.ID,
geometryMatrix, matrix.IdentityColor())
g.flush()
}

View File

@ -113,11 +113,13 @@ func (context *GraphicsContext) DrawRect(rect graphics.Rect, clr color.Color) {
}
func (context *GraphicsContext) DrawTexture(
texture graphics.Texture,
textureID graphics.TextureID,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
source := graphics.Rect{0, 0, texture.Width, texture.Height}
texture := context.textures[textureID]
source := graphics.Rect{0, 0, texture.width, texture.height}
locations := []graphics.TexturePart{{0, 0, source}}
context.DrawTextureParts(texture.ID, locations,
context.DrawTextureParts(textureID, locations,
geometryMatrix, colorMatrix)
}