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" "time"
) )
type TapInfo struct {
X int
Y int
}
type Game interface { type Game interface {
ScreenWidth() int ScreenWidth() int
ScreenHeight() int ScreenHeight() int
@ -20,7 +25,7 @@ type UI interface {
func OpenGLRun(game Game, ui UI, screenScale int) { func OpenGLRun(game Game, ui UI, screenScale int) {
ch := make(chan bool, 1) ch := make(chan bool, 1)
device := opengl.NewDevice( graphicsDevice := opengl.NewDevice(
game.ScreenWidth(), game.ScreenHeight(), screenScale, game.ScreenWidth(), game.ScreenHeight(), screenScale,
func(g graphics.GraphicsContext, offscreen graphics.Texture) { func(g graphics.GraphicsContext, offscreen graphics.Texture) {
ticket := <-ch ticket := <-ch
@ -39,7 +44,7 @@ func OpenGLRun(game Game, ui UI, screenScale int) {
} }
}() }()
game.Init(device.TextureFactory()) game.Init(graphicsDevice.TextureFactory())
ch <- true 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.SetOffscreen(offscreen.ID)
g.DrawTexture(game.rectsTexture, g.DrawTexture(game.rectsTexture.ID,
matrix.IdentityGeometry(), matrix.IdentityGeometry(),
matrix.IdentityColor()) matrix.IdentityColor())
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -113,11 +113,13 @@ func (context *GraphicsContext) DrawRect(rect graphics.Rect, clr color.Color) {
} }
func (context *GraphicsContext) DrawTexture( func (context *GraphicsContext) DrawTexture(
texture graphics.Texture, textureID graphics.TextureID,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { 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}} locations := []graphics.TexturePart{{0, 0, source}}
context.DrawTextureParts(texture.ID, locations, context.DrawTextureParts(textureID, locations,
geometryMatrix, colorMatrix) geometryMatrix, colorMatrix)
} }