add draw rect and new surface

This commit is contained in:
cuu
2018-06-06 20:49:46 +08:00
parent 2a2e793bc9
commit ed742048f4
11 changed files with 902 additions and 508 deletions

View File

@@ -1,10 +1,22 @@
package surface
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"../color"
)
func Fill(surface *sdl.Surface, col color.Color) {
rect := sdl.Rect{0,0,0,0}
rect.W = surface.W
rect.H = surface.H
FillRect(surface, &rect, uint32(col.ToHex()))
}
func FillRect(surface *sdl.Surface,rect *sdl.Rect, color uint32) {
sdl.Do(func() {
@@ -14,3 +26,21 @@ func FillRect(surface *sdl.Surface,rect *sdl.Rect, color uint32) {
return
}
// Create a New Surface
func Surface(w,h int) *sdl.Surface {
//flags=0, depth=0, masks=None
Rmask := 0x000000ff
Gmask := 0x0000ff00
Bmask := 0x00ff0000
Amask := 0xff000000
flags := 0
depth := 32
surf,err := sdl.CreateRGBSurface(uint32(flags),int32(w),int32(h), int32(depth), uint32(Rmask), uint32(Gmask), uint32(Bmask), uint32(Amask))
if err != nil {
panic( fmt.Sprintf("sdl.CreateRGBSurface failed %s",sdl.GetError()))
}
return surf
}