-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a transparent texture example and go fmt'd all the examples
Signed-off-by: Jacky Boen <[email protected]>
- Loading branch information
Jacky Boen
committed
Jul 16, 2014
1 parent
e70fda6
commit 05a7bff
Showing
8 changed files
with
98 additions
and
36 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,2 @@ | ||
*.bmp | ||
*.png |
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
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
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 |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
package main | ||
|
||
import ( | ||
"github.com/veandco/go-sdl2/sdl" | ||
"fmt" | ||
"github.com/veandco/go-sdl2/sdl" | ||
"os" | ||
) | ||
|
||
|
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
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,62 @@ | ||
// author: Jacky Boen | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/veandco/go-sdl2/sdl" | ||
"github.com/veandco/go-sdl2/sdl_image" | ||
"os" | ||
) | ||
|
||
var winTitle string = "Go-SDL2 Texture" | ||
var winWidth, winHeight int = 800, 600 | ||
var imageName string = "test.png" | ||
|
||
func main() { | ||
var window *sdl.Window | ||
var renderer *sdl.Renderer | ||
var texture *sdl.Texture | ||
var src, dst sdl.Rect | ||
|
||
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, | ||
winWidth, winHeight, sdl.WINDOW_SHOWN) | ||
if window == nil { | ||
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError()) | ||
os.Exit(1) | ||
} | ||
|
||
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED) | ||
if renderer == nil { | ||
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError()) | ||
os.Exit(2) | ||
} | ||
|
||
image := img.Load(imageName) | ||
if image == nil { | ||
fmt.Fprintf(os.Stderr, "Failed to load PNG: %s\n", sdl.GetError()) | ||
os.Exit(3) | ||
} | ||
|
||
texture = renderer.CreateTextureFromSurface(image) | ||
if texture == nil { | ||
fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", sdl.GetError()) | ||
os.Exit(4) | ||
} | ||
|
||
src = sdl.Rect{0, 0, 512, 512} | ||
dst = sdl.Rect{100, 50, 512, 512} | ||
|
||
renderer.Clear() | ||
renderer.SetDrawColor(255, 0, 0, 255) | ||
renderer.FillRect(&sdl.Rect{0, 0, int32(winWidth), int32(winHeight)}) | ||
renderer.Copy(texture, &src, &dst) | ||
renderer.Present() | ||
|
||
sdl.Delay(2000) | ||
|
||
image.Free() | ||
texture.Destroy() | ||
renderer.Destroy() | ||
window.Destroy() | ||
} |
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