Skip to content

Commit a6e31f9

Browse files
authored
Merge pull request #2 from dusk125/update-pixel
Update pixel, beep to v2
2 parents cb527ea + 24d34f2 commit a6e31f9

File tree

55 files changed

+380
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+380
-395
lines changed

community/amidakuji/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ $ make
7777

7878
#### Library
7979
- [Pixel](https://github.com/gopxl/pixel/v2/tree/7cff3ce3aed80129b7b1dd57e63439426e11b6ee)
80-
- [Beep](https://github.com/gopxl/beep/tree/63cc6fbbac46dba1a03e55f0ebc965d6c82ca8e1)
80+
- [Beep](https://github.com/gopxl/beep/v2/tree/63cc6fbbac46dba1a03e55f0ebc965d6c82ca8e1)
8181
- [GLFW 3.2](https://github.com/go-gl/glfw/tree/513e4f2bf85c31fba0fc4907abd7895242ccbe50/v3.2/glfw)
8282
- [dialog](https://github.com/sqweek/dialog/tree/2f9d9e5dd848a3bad4bdd0210c73bb90c13a3791)
8383

community/amidakuji/game.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"time"
1616
"unsafe"
1717

18+
glfw "github.com/go-gl/glfw/v3.2/glfw"
1819
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
1920
"github.com/gopxl/pixel-examples/community/amidakuji/glossary/jukebox"
20-
glfw "github.com/go-gl/glfw/v3.2/glfw"
2121

2222
"github.com/gopxl/pixel/v2"
23-
"github.com/gopxl/pixel/v2/pixelgl"
24-
"github.com/gopxl/pixel/v2/text"
23+
"github.com/gopxl/pixel/v2/backends/opengl"
24+
"github.com/gopxl/pixel/v2/ext/text"
2525
"github.com/sqweek/dialog"
2626
"golang.org/x/image/colornames"
2727
)
@@ -49,7 +49,7 @@ type Updater interface {
4949
// Also it manages and draws everything about...
5050
type game struct {
5151
// something system, somthing runtime
52-
window *pixelgl.Window // lazy init
52+
window *opengl.Window // lazy init
5353
bg pixel.RGBA
5454
camera *gg.Camera // lazy init
5555
fpsw *gg.FPSWatch
@@ -429,7 +429,7 @@ func (g *game) Resume() {
429429

430430
func (g *game) SetFullScreenMode(on bool) {
431431
if on {
432-
monitor := pixelgl.PrimaryMonitor()
432+
monitor := opengl.PrimaryMonitor()
433433
width, height := monitor.Size()
434434
// log.Println(monitor.VideoModes()) //
435435
g.window.SetMonitor(monitor)
@@ -447,7 +447,7 @@ func (g *game) SetFullScreenMode(on bool) {
447447
// Read only methods
448448

449449
// WindowDeep is a hacky way to access a window in deep.
450-
// It returns (window *glfw.Window) which is an unexported member inside a (*pixelgl.Window).
450+
// It returns (window *glfw.Window) which is an unexported member inside a (*opengl.Window).
451451
// Read only argument game ignores the pass lock by value warning.
452452
func (g game) WindowDeep() (baseWindow *glfw.Window) {
453453
return *(**glfw.Window)(unsafe.Pointer(reflect.Indirect(reflect.ValueOf(g.window)).FieldByName("window").UnsafeAddr()))
@@ -470,15 +470,15 @@ func (g game) BridgesCount() (sum int) {
470470

471471
// Run the game window and its event loop on main thread.
472472
func (g *game) Run() {
473-
pixelgl.Run(func() {
473+
opengl.Run(func() {
474474
g.RunLazyInit()
475475
g.RunEventLoop()
476476
})
477477
}
478478

479479
func (g *game) RunLazyInit() {
480480
// This window will show up as soon as it is created.
481-
win, err := pixelgl.NewWindow(pixelgl.WindowConfig{
481+
win, err := opengl.NewWindow(opengl.WindowConfig{
482482
Title: title + " (" + version + ")",
483483
Icon: nil,
484484
Bounds: pixel.R(0, 0, g.winWidth, g.winHeight),
@@ -492,8 +492,8 @@ func (g *game) RunLazyInit() {
492492
}
493493
win.SetSmooth(true)
494494

495-
MoveWindowToCenterOfPrimaryMonitor := func(win *pixelgl.Window) {
496-
vmodes := pixelgl.PrimaryMonitor().VideoModes()
495+
MoveWindowToCenterOfPrimaryMonitor := func(win *opengl.Window) {
496+
vmodes := opengl.PrimaryMonitor().VideoModes()
497497
vmodesLast := vmodes[len(vmodes)-1]
498498
biggestResolution := pixel.R(0, 0, float64(vmodesLast.Width), float64(vmodesLast.Height))
499499
win.SetPos(biggestResolution.Center().Sub(win.Bounds().Center()))
@@ -558,15 +558,15 @@ func (g *game) HandlingEvents(dt float64) {
558558
// Notice that all function calls as go routine are non-blocking, but the others will block the main thread.
559559

560560
// system
561-
if g.window.JustReleased(pixelgl.KeyEscape) {
561+
if g.window.JustReleased(pixel.KeyEscape) {
562562
g.window.SetClosed(true)
563563
}
564-
if g.window.JustReleased(pixelgl.KeySpace) {
564+
if g.window.JustReleased(pixel.KeySpace) {
565565
g.Pause()
566566
dialog.Message("%s", "Pause").Title("PPAP").Info()
567567
g.Resume()
568568
}
569-
if g.window.JustReleased(pixelgl.KeyTab) {
569+
if g.window.JustReleased(pixel.KeyTab) {
570570
if g.window.Monitor() == nil {
571571
g.SetFullScreenMode(true)
572572
} else {
@@ -575,12 +575,12 @@ func (g *game) HandlingEvents(dt float64) {
575575
}
576576

577577
// scalpel mode
578-
if g.window.JustReleased(pixelgl.MouseButtonRight) {
578+
if g.window.JustReleased(pixel.MouseButtonRight) {
579579
go func() {
580580
g.isScalpelMode = !g.isScalpelMode
581581
}()
582582
}
583-
if g.window.JustReleased(pixelgl.MouseButtonLeft) {
583+
if g.window.JustReleased(pixel.MouseButtonLeft) {
584584
// ---------------------------------------------------
585585
if !jukebox.IsPlaying() {
586586
jukebox.Play()
@@ -613,18 +613,18 @@ func (g *game) HandlingEvents(dt float64) {
613613
}
614614

615615
// game ctrl
616-
if g.window.JustReleased(pixelgl.Key1) { // shuffle
616+
if g.window.JustReleased(pixel.Key1) { // shuffle
617617
go func() {
618618
g.Shuffle(10, 750)
619619
}()
620620
}
621-
if g.window.JustReleased(pixelgl.Key2) { // find path slow
621+
if g.window.JustReleased(pixel.Key2) { // find path slow
622622
go func() {
623623
g.ResetPaths()
624624
g.AnimatePaths(g.AnimatePath)
625625
}()
626626
}
627-
if g.window.JustReleased(pixelgl.Key3) { // find path fast
627+
if g.window.JustReleased(pixel.Key3) { // find path fast
628628
go func() {
629629
g.ResetPaths()
630630
g.AnimatePaths(func(participant int) {
@@ -634,27 +634,27 @@ func (g *game) HandlingEvents(dt float64) {
634634
}
635635

636636
// camera
637-
if g.window.JustReleased(pixelgl.KeyEnter) {
637+
if g.window.JustReleased(pixel.KeyEnter) {
638638
go func() {
639639
g.camera.Rotate(-90)
640640
}()
641641
}
642-
if g.window.Pressed(pixelgl.KeyRight) {
642+
if g.window.Pressed(pixel.KeyRight) {
643643
go func(dt float64) { // This camera will go diagonal while the case is in middle of rotating the camera.
644644
g.camera.Move(pixel.V(1000*dt, 0).Rotated(-g.camera.Angle()))
645645
}(dt)
646646
}
647-
if g.window.Pressed(pixelgl.KeyLeft) {
647+
if g.window.Pressed(pixel.KeyLeft) {
648648
go func(dt float64) {
649649
g.camera.Move(pixel.V(-1000*dt, 0).Rotated(-g.camera.Angle()))
650650
}(dt)
651651
}
652-
if g.window.Pressed(pixelgl.KeyUp) {
652+
if g.window.Pressed(pixel.KeyUp) {
653653
go func(dt float64) {
654654
g.camera.Move(pixel.V(0, 1000*dt).Rotated(-g.camera.Angle()))
655655
}(dt)
656656
}
657-
if g.window.Pressed(pixelgl.KeyDown) {
657+
if g.window.Pressed(pixel.KeyDown) {
658658
go func(dt float64) {
659659
g.camera.Move(pixel.V(0, -1000*dt).Rotated(-g.camera.Angle()))
660660
}(dt)

community/amidakuji/glossary/cam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"math"
55

66
"github.com/gopxl/pixel/v2"
7-
"github.com/gopxl/pixel/v2/imdraw"
7+
"github.com/gopxl/pixel/v2/ext/imdraw"
88
"golang.org/x/image/colornames"
99
)
1010

community/amidakuji/glossary/explosive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync"
77

88
"github.com/gopxl/pixel/v2"
9-
"github.com/gopxl/pixel/v2/imdraw"
9+
"github.com/gopxl/pixel/v2/ext/imdraw"
1010
)
1111

1212
// -------------------------------------------------------------------------

community/amidakuji/glossary/fpschk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"time"
88

99
"github.com/gopxl/pixel/v2"
10-
"github.com/gopxl/pixel/v2/imdraw"
11-
"github.com/gopxl/pixel/v2/text"
10+
"github.com/gopxl/pixel/v2/ext/imdraw"
11+
"github.com/gopxl/pixel/v2/ext/text"
1212
"golang.org/x/image/colornames"
1313
)
1414

community/amidakuji/glossary/jukebox/music.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
1111

12-
"github.com/gopxl/beep"
13-
"github.com/gopxl/beep/speaker"
14-
"github.com/gopxl/beep/vorbis"
12+
"github.com/gopxl/beep/v2"
13+
"github.com/gopxl/beep/v2/speaker"
14+
"github.com/gopxl/beep/v2/vorbis"
1515
)
1616

1717
// -------------------------------------------------------------------------

community/amidakuji/glossary/starfield.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync"
77

88
"github.com/gopxl/pixel/v2"
9-
"github.com/gopxl/pixel/v2/imdraw"
9+
"github.com/gopxl/pixel/v2/ext/imdraw"
1010
)
1111

1212
// -------------------------------------------------------------------------

community/amidakuji/glossary/util.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
_ "image/gif"
1414
_ "image/png"
1515

16-
"github.com/gopxl/pixel/v2"
17-
"github.com/gopxl/pixel/v2/text"
1816
"github.com/golang/freetype/truetype"
17+
"github.com/gopxl/pixel/v2"
18+
"github.com/gopxl/pixel/v2/ext/text"
1919
"golang.org/x/image/font"
2020
"golang.org/x/image/font/basicfont"
2121
)
@@ -32,6 +32,19 @@ func AtlasASCII() *text.Atlas {
3232
return atlasASCII
3333
}
3434

35+
func Asset(name string) ([]byte, error) {
36+
return ioutil.ReadFile(name)
37+
}
38+
39+
func AssetDir(name string) ([]string, error) {
40+
f, err := os.Open(name)
41+
if err != nil {
42+
return nil, err
43+
}
44+
defer f.Close()
45+
return f.Readdirnames(-1)
46+
}
47+
3548
// NewAtlas newly loads and prepares a set of images of characters or symbols to be drawn.
3649
// Arg runeSet would be set to nil if non-ASCII characters are not in use.
3750
func NewAtlas(nameAssetTTF string, size float64, runeSet []rune) *text.Atlas {

community/amidakuji/ladder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
88

99
"github.com/gopxl/pixel/v2"
10-
"github.com/gopxl/pixel/v2/imdraw"
10+
"github.com/gopxl/pixel/v2/ext/imdraw"
1111
"golang.org/x/image/colornames"
1212
)
1313

community/amidakuji/nametag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
88

99
"github.com/gopxl/pixel/v2"
10-
"github.com/gopxl/pixel/v2/imdraw"
11-
"github.com/gopxl/pixel/v2/text"
10+
"github.com/gopxl/pixel/v2/ext/imdraw"
11+
"github.com/gopxl/pixel/v2/ext/text"
1212
"golang.org/x/image/colornames"
1313
)
1414

community/amidakuji/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
88

99
"github.com/gopxl/pixel/v2"
10-
"github.com/gopxl/pixel/v2/imdraw"
10+
"github.com/gopxl/pixel/v2/ext/imdraw"
1111
)
1212

1313
// Path is for animating a path to the prize in a ladder.

community/amidakuji/scalpel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
gg "github.com/gopxl/pixel-examples/community/amidakuji/glossary"
88

99
"github.com/gopxl/pixel/v2"
10-
"github.com/gopxl/pixel/v2/imdraw"
10+
"github.com/gopxl/pixel/v2/ext/imdraw"
1111
"golang.org/x/image/colornames"
1212
)
1313

community/bouncing/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bouncing
22

3-
Bouncing particles using the [imdraw](https://godoc.org/github.com/gopxl/pixel/v2/imdraw) package.
3+
Bouncing particles using the [imdraw](https://godoc.org/github.com/gopxl/pixel/v2/ext/imdraw) package.
44

55
Made by [Peter Hellberg](https://github.com/peterhellberg/) as part of his [pixel-experiments](https://github.com/peterhellberg/pixel-experiments)
66

community/bouncing/bouncing.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"time"
88

99
"github.com/gopxl/pixel/v2"
10-
"github.com/gopxl/pixel/v2/imdraw"
11-
"github.com/gopxl/pixel/v2/pixelgl"
10+
"github.com/gopxl/pixel/v2/backends/opengl"
11+
"github.com/gopxl/pixel/v2/ext/imdraw"
1212
)
1313

1414
var (
@@ -23,7 +23,7 @@ var (
2323
)
2424

2525
func run() {
26-
win, err := pixelgl.NewWindow(pixelgl.WindowConfig{
26+
win, err := opengl.NewWindow(opengl.WindowConfig{
2727
Bounds: pixel.R(0, 0, w, h),
2828
VSync: true,
2929
Undecorated: true,
@@ -49,15 +49,15 @@ func run() {
4949
}()
5050

5151
for !win.Closed() {
52-
win.SetClosed(win.JustPressed(pixelgl.KeyEscape) || win.JustPressed(pixelgl.KeyQ))
52+
win.SetClosed(win.JustPressed(pixel.KeyEscape) || win.JustPressed(pixel.KeyQ))
5353

54-
if win.JustPressed(pixelgl.KeySpace) {
54+
if win.JustPressed(pixel.KeySpace) {
5555
for _, ball := range balls {
5656
ball.color = ball.palette.next()
5757
}
5858
}
5959

60-
if win.JustPressed(pixelgl.KeyEnter) {
60+
if win.JustPressed(pixel.KeyEnter) {
6161
for _, ball := range balls {
6262
ball.pos = center()
6363
ball.vel = randomVelocity()
@@ -117,7 +117,7 @@ func main() {
117117
}
118118
}()
119119

120-
pixelgl.Run(run)
120+
opengl.Run(run)
121121
}
122122

123123
func newParticleAt(pos, vel pixel.Vec) *particle {

community/game_of_life/life/grid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package life
22

33
import (
44
"github.com/gopxl/pixel/v2"
5-
"github.com/gopxl/pixel/v2/imdraw"
5+
"github.com/gopxl/pixel/v2/ext/imdraw"
66
"golang.org/x/image/colornames"
77
)
88

community/game_of_life/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77

88
"golang.org/x/image/colornames"
99

10-
"github.com/gopxl/pixel/v2"
1110
"github.com/gopxl/pixel-examples/community/game_of_life/life"
12-
"github.com/gopxl/pixel/v2/imdraw"
13-
"github.com/gopxl/pixel/v2/pixelgl"
11+
"github.com/gopxl/pixel/v2"
12+
"github.com/gopxl/pixel/v2/backends/opengl"
13+
"github.com/gopxl/pixel/v2/ext/imdraw"
1414
)
1515

1616
var (
@@ -28,17 +28,17 @@ func init() {
2828
}
2929

3030
func main() {
31-
pixelgl.Run(run)
31+
opengl.Run(run)
3232
}
3333

3434
func run() {
3535

36-
cfg := pixelgl.WindowConfig{
36+
cfg := opengl.WindowConfig{
3737
Title: "Pixel Rocks!",
3838
Bounds: pixel.R(0, 0, *windowSize, *windowSize),
3939
VSync: true,
4040
}
41-
win, err := pixelgl.NewWindow(cfg)
41+
win, err := opengl.NewWindow(cfg)
4242
if err != nil {
4343
panic(err)
4444
}

0 commit comments

Comments
 (0)