-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurface.go
114 lines (106 loc) · 3.06 KB
/
surface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package sdl
// #cgo pkg-config: sdl2
// #include <SDL2/SDL.h>
import "C"
import "encoding/binary"
import "image"
type Surface struct {
cSurface *C.SDL_Surface
}
// CreateSurface returns a newly allocated surface.
//
// Note: Free must be called when finished using the surface.
func CreateSurface(w, h int) (surface *Surface, err error) {
surface = new(Surface)
// SDL_PIXELFORMAT_RGBA8888
rMask := C.Uint32(0xFF000000)
gMask := C.Uint32(0x00FF0000)
bMask := C.Uint32(0x0000FF00)
aMask := C.Uint32(0x000000FF)
if nativeEndian == binary.BigEndian {
// SDL_PIXELFORMAT_ABGR8888
rMask = 0x000000FF
gMask = 0x0000FF00
bMask = 0x00FF0000
aMask = 0xFF000000
}
surface.cSurface = C.SDL_CreateRGBSurface(0, C.int(w), C.int(h), 32, rMask, gMask, bMask, aMask)
if surface.cSurface == nil {
return nil, getError()
}
return surface, nil
}
// Free frees a surface.
func (surface *Surface) Free() {
C.SDL_FreeSurface(surface.cSurface)
}
// Blit performs a fast blit from the source surface to the destination surface.
//
// srcRect represents the rectangle to be copied or image.ZR to copy the entire
// surface.
//
// dstPoint represents the destination position.
func (src *Surface) Blit(srcRect image.Rectangle, dst *Surface, dstPoint image.Point) (err error) {
cSrcRect := cRect(srcRect)
cDstRect := new(C.SDL_Rect)
cDstRect.x = C.int(dstPoint.X)
cDstRect.y = C.int(dstPoint.Y)
if C.SDL_BlitSurface(src.cSurface, cSrcRect, dst.cSurface, cDstRect) != 0 {
return getError()
}
return nil
}
// BlitScaled performs a scaled fast blit from the source surface to the
// destination surface.
//
// srcRect represents the rectangle to be copied or image.ZR to copy the entire
// surface.
//
// dstRect represents the rectangle to be copied into.
//
// If the srcRect and dstRect differs in size, the surface will be scaled to
// fit.
func (src *Surface) BlitScaled(srcRect image.Rectangle, dst *Surface, dstRect image.Rectangle) (err error) {
cSrcRect := cRect(srcRect)
cDstRect := cRect(dstRect)
if C.SDL_BlitScaled(src.cSurface, cSrcRect, dst.cSurface, cDstRect) != 0 {
return getError()
}
return nil
}
/*
SDL_BlitScaled [done] (SDL_UpperBlitScaled)
SDL_BlitSurface [done] (SDL_UpperBlit)
SDL_ConvertPixels
SDL_ConvertSurface
SDL_ConvertSurfaceFormat
SDL_CreateRGBSurface [done]
SDL_CreateRGBSurfaceFrom
SDL_FillRect
SDL_FillRects
SDL_FreeSurface [done]
SDL_GetClipRect
SDL_GetColorKey
SDL_GetSurfaceAlphaMod
SDL_GetSurfaceBlendMode
SDL_GetSurfaceColorMod
SDL_LoadBMP
SDL_LoadBMP_RW
SDL_LockSurface
SDL_LowerBlit #skip#
SDL_LowerBlitScaled #skip#
SDL_MUSTLOCK
SDL_SaveBMP
SDL_SaveBMP_RW
SDL_SetClipRect
SDL_SetColorKey
SDL_SetSurfaceAlphaMod
SDL_SetSurfaceBlendMode
SDL_SetSurfaceColorMod
SDL_SetSurfacePalette
SDL_SetSurfaceRLE
SDL_SoftStretch
SDL_UnlockSurface
SDL_UpperBlit #skip#
SDL_UpperBlitScaled #skip#
*/