-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Ray
committed
Aug 30, 2024
1 parent
688fdc8
commit 214000d
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"image/jpeg" | ||
"image/png" | ||
|
||
"github.com/gopxl/pixel/v2" | ||
"github.com/gopxl/pixel/v2/backends/opengl" | ||
"golang.org/x/image/colornames" | ||
) | ||
|
||
func main() { | ||
opengl.Run(run) | ||
} | ||
|
||
func run() { | ||
cfg := opengl.WindowConfig{ | ||
Title: "Image Loading", | ||
Bounds: pixel.R(0, 0, 1024, 768), | ||
} | ||
|
||
win, err := opengl.NewWindow(cfg) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer win.Destroy() | ||
|
||
p1, err := pixel.PictureDataFromFile("../hiking.png", png.Decode) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
p2, err := pixel.PictureDataFromFile("../hiking.jpeg", jpeg.Decode) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
spr1 := pixel.NewSprite(p1, p1.Bounds()) | ||
spr2 := pixel.NewSprite(p2, p2.Bounds()) | ||
|
||
for !win.Closed() { | ||
if win.JustReleased(pixel.KeyEscape) { | ||
win.SetClosed(true) | ||
} | ||
|
||
win.Clear(colornames.Skyblue) | ||
|
||
spr1.Draw(win, pixel.IM.Moved(win.Bounds().Center().Add(pixel.V(0, 100)))) | ||
spr2.Draw(win, pixel.IM.Moved(win.Bounds().Center().Add(pixel.V(0, -100)))) | ||
|
||
win.Update() | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
// Since we're using a nil decoder, we need to import these to register the formats. | ||
_ "image/jpeg" | ||
_ "image/png" | ||
|
||
"github.com/gopxl/pixel/v2" | ||
"github.com/gopxl/pixel/v2/backends/opengl" | ||
"golang.org/x/image/colornames" | ||
) | ||
|
||
func main() { | ||
opengl.Run(run) | ||
} | ||
|
||
func run() { | ||
cfg := opengl.WindowConfig{ | ||
Title: "Image Loading", | ||
Bounds: pixel.R(0, 0, 1024, 768), | ||
} | ||
|
||
win, err := opengl.NewWindow(cfg) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer win.Destroy() | ||
|
||
p1, err := pixel.PictureDataFromFile("../hiking.png", nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
p2, err := pixel.PictureDataFromFile("../hiking.jpeg", nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
spr1 := pixel.NewSprite(p1, p1.Bounds()) | ||
spr2 := pixel.NewSprite(p2, p2.Bounds()) | ||
|
||
for !win.Closed() { | ||
if win.JustReleased(pixel.KeyEscape) { | ||
win.SetClosed(true) | ||
} | ||
|
||
win.Clear(colornames.Skyblue) | ||
|
||
spr1.Draw(win, pixel.IM.Moved(win.Bounds().Center().Add(pixel.V(0, 100)))) | ||
spr2.Draw(win, pixel.IM.Moved(win.Bounds().Center().Add(pixel.V(0, -100)))) | ||
|
||
win.Update() | ||
} | ||
} |