Advertisement
Guest User

Untitled

a guest
Aug 31st, 2019
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "github.com/veandco/go-sdl2/sdl"
  5. )
  6.  
  7. func main() {
  8.     alive := true
  9.     window, _ := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 200, 200, sdl.WINDOW_SHOWN)
  10.     renderer, _ := sdl.CreateRenderer(window, -1, sdl.RENDERER_PRESENTVSYNC|sdl.RENDERER_TARGETTEXTURE|sdl.RENDERER_ACCELERATED)
  11.  
  12.     renderer.SetDrawColor(80, 80, 80, 255)
  13.     renderer.Clear()
  14.  
  15.     for alive {
  16.  
  17.         // create some texture
  18.         texture, _ := renderer.CreateTexture(sdl.PIXELFORMAT_RGBA8888, sdl.TEXTUREACCESS_TARGET, 100, 100)
  19.  
  20.         renderer.SetRenderTarget(texture)                        // Set texture as target
  21.         renderer.SetDrawColor(0xDD, 0x88, 0x33, 0xFF)            //
  22.         renderer.Clear()                                         // Set some orange as background
  23.         renderer.SetDrawColor(0x33, 0x88, 0xFF, 0xFF)            //
  24.         renderer.FillRect(&sdl.Rect{X: 10, Y: 10, W: 80, H: 80}) // Draw some blue rect on it
  25.  
  26.         renderer.SetRenderTarget(nil)                                        // Reset rendertarget to window
  27.         renderer.Copy(texture, nil, &sdl.Rect{X: 50, Y: 50, W: 100, H: 100}) // draw texture on window
  28.  
  29.         //texture.Destroy()  // when to destroy the texture ?
  30.         renderer.Present() // neither of this works. If I delete the texture (even AFTER .Present)
  31.         //texture.Destroy()  // it wont work right and the blue rect disappears. The .Clear orange color stays though...
  32.  
  33.         for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
  34.             switch event.GetType() {
  35.             case sdl.QUIT:
  36.                 alive = false
  37.             }
  38.         }
  39.  
  40.     }
  41.  
  42.     renderer.Destroy()
  43.     window.Destroy()
  44.  
  45. }
Advertisement
RAW Paste Data Copied
Advertisement