mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Change the signiture of GraphicsContext.DrawTexture
This commit is contained in:
parent
81a7d4c4fd
commit
92ac4b97ea
11
ebiten.go
11
ebiten.go
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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())
|
||||||
}
|
}
|
||||||
|
@ -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())
|
||||||
}
|
}
|
||||||
|
@ -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(),
|
||||||
|
@ -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()
|
||||||
|
@ -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 {
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user