mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Improve alphablending example
This commit is contained in:
parent
df35a0ce1e
commit
d4cd858eeb
@ -37,16 +37,19 @@ type Game struct {
|
||||
|
||||
func (g *Game) Update(gr ebiten.GraphicsContext) error {
|
||||
g.count++
|
||||
g.count %= 120
|
||||
diff := float64(g.count) * 0.5
|
||||
if 60 < g.count {
|
||||
diff = float64(120-g.count) * 0.5
|
||||
g.count %= 600
|
||||
diff := float64(g.count) * 0.2
|
||||
switch {
|
||||
case 480 < g.count:
|
||||
diff = 0
|
||||
case 240 < g.count:
|
||||
diff = float64(480-g.count) * 0.2
|
||||
}
|
||||
|
||||
gr.PushRenderTarget(g.tmpRenderTarget)
|
||||
gr.Clear()
|
||||
for i := 0; i < 10; i++ {
|
||||
geo := ebiten.TranslateGeometry(15+float64(i)*(20+diff), 20)
|
||||
geo := ebiten.TranslateGeometry(15+float64(i)*(diff), 20)
|
||||
clr := ebiten.ScaleColor(color.RGBA{0xff, 0xff, 0xff, 0x80})
|
||||
ebiten.DrawWholeTexture(gr, g.ebitenTexture, geo, clr)
|
||||
}
|
||||
@ -54,7 +57,7 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error {
|
||||
|
||||
gr.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff})
|
||||
for i := 0; i < 10; i++ {
|
||||
geo := ebiten.TranslateGeometry(0, float64(i)*(10+diff))
|
||||
geo := ebiten.TranslateGeometry(0, float64(i)*(diff))
|
||||
clr := ebiten.ColorMatrixI()
|
||||
ebiten.DrawWholeTexture(gr, g.tmpRenderTarget.Texture(), geo, clr)
|
||||
}
|
||||
|
@ -96,6 +96,8 @@ func (c *graphicsContext) preUpdate() {
|
||||
func (c *graphicsContext) postUpdate() {
|
||||
c.PopRenderTarget()
|
||||
|
||||
// We don't need to clear the default render target (framebuffer).
|
||||
// For the default framebuffer, a special shader is used.
|
||||
scale := float64(c.screenScale)
|
||||
geo := ScaleGeometry(scale, scale)
|
||||
clr := ColorMatrixI()
|
||||
|
@ -86,22 +86,15 @@ func createFramebuffer(nativeTexture gl.Texture) (gl.Framebuffer, error) {
|
||||
framebuffer := gl.GenFramebuffer()
|
||||
framebuffer.Bind()
|
||||
|
||||
if err := framebufferTexture(nativeTexture); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return framebuffer, nil
|
||||
}
|
||||
|
||||
func framebufferTexture(nativeTexture gl.Texture) error {
|
||||
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, nativeTexture, 0)
|
||||
if gl.CheckFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE {
|
||||
return errors.New("creating framebuffer failed")
|
||||
return 0, errors.New("creating framebuffer failed")
|
||||
}
|
||||
|
||||
gl.ClearColor(0, 0, 0, 0)
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
return nil
|
||||
|
||||
return framebuffer, nil
|
||||
}
|
||||
|
||||
func (r *RenderTarget) SetAsViewport() error {
|
||||
|
Loading…
Reference in New Issue
Block a user