Skip to content

Instantly share code, notes, and snippets.

@avdept
Created May 25, 2015 20:30
Show Gist options
  • Save avdept/d3d39cc01119ba6daf9b to your computer and use it in GitHub Desktop.
Save avdept/d3d39cc01119ba6daf9b to your computer and use it in GitHub Desktop.
window with sdl2 and texture golang
package main
import (
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/sdl_image"
"fmt"
)
const(
SCREEN_WIDTH int = 1440
SCREEN_HEIGHT int = 900
)
var bmp string = "123.jpg"
func main(){
sdl.Init(sdl.INIT_EVERYTHING)
window, err:= sdl.CreateWindow("Gudzilla Power", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
renderer, render_error := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
img, img_error := img.Load(bmp)
if img_error != nil {
fmt.Println(img_error)
}
tex, tex_err := renderer.CreateTextureFromSurface(img)
renderer.Clear()
renderer.Copy(tex, nil, nil)
renderer.Present()
sdl.Delay(1000)
if tex_err != nil {
panic(tex_err)
}
if img_error != nil {
panic(img_error)
}
if render_error != nil {
panic(render_error)
}
fmt.Scanln()
img.Free()
cleanup(renderer, tex, window)
sdl.Quit()
}
func cleanup(renderer *sdl.Renderer, texture *sdl.Texture, window sdl.Window){
texture.Destroy()
renderer.Destroy()
window.Destroy()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment