Created
December 23, 2010 17:16
-
-
Save mk0x9/753259 to your computer and use it in GitHub Desktop.
sdl.go
This file contains hidden or 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
package sdl | |
// #include "SDL/SDL.h" | |
// #include "SDL/SDL_image.h" | |
import "C" | |
import ( | |
"unsafe" | |
) | |
type Surface struct { | |
surface *C.SDL_Surface | |
} | |
type Event struct { | |
event *C.SDL_Event | |
} | |
func Init(flags uint32) int { | |
return int(C.SDL_Init(C.Uint32(flags))) | |
} | |
func Quit() { | |
C.SDL_Quit() | |
} | |
func SetVideoMode(width, height, bpp int, flags uint32) *Surface { | |
surface := new(Surface) | |
surface.surface = C.SDL_SetVideoMode(C.int(width), C.int(height), C.int(bpp), C.Uint32(flags)) | |
return surface | |
} | |
func (surface *Surface) LoadBMP(filename string) uintptr { | |
if surface.surface != nil { | |
surface.FreeSurface() | |
} | |
surface.surface = C.SDL_LoadBMP_RW(C.SDL_RWFromFile(C.CString(filename), C.CString("rb")), C.int(1)) | |
return uintptr(unsafe.Pointer(surface.surface)) | |
} | |
func (surface *Surface) IMGLoad(filename string) uintptr { | |
surface.surface = C.IMG_Load(C.CString(filename)) | |
return uintptr(unsafe.Pointer(surface.surface)) | |
} | |
func (surface *Surface) FreeSurface() { | |
C.SDL_FreeSurface(surface.surface) | |
} | |
func (surface *Surface) Blit(source *Surface, srcrect, dstrect *Rect) int { | |
var _srcrect *C.SDL_Rect | |
var _dstrect *C.SDL_Rect | |
if srcrect != nil { | |
_srcrect = new(C.SDL_Rect) | |
_srcrect.x = C.Sint16(srcrect.X) | |
_srcrect.y = C.Sint16(srcrect.Y) | |
_srcrect.w = C.Uint16(srcrect.W) | |
_srcrect.h = C.Uint16(srcrect.H) | |
} | |
if dstrect != nil { | |
_dstrect = new(C.SDL_Rect) | |
_dstrect.x = C.Sint16(dstrect.X) | |
_dstrect.y = C.Sint16(dstrect.Y) | |
_dstrect.w = C.Uint16(dstrect.W) | |
_dstrect.h = C.Uint16(dstrect.H) | |
} | |
return int(C.SDL_BlitSurface(source.surface, _srcrect, surface.surface, _dstrect)) | |
} | |
func Delay(ms uint32) { | |
C.SDL_Delay(C.Uint32(ms)) | |
} | |
func (surface *Surface) Flip() int { | |
return int(C.SDL_Flip(surface.surface)) | |
} | |
func (surface *Surface) DisplayFormat() { | |
defer C.SDL_FreeSurface(surface.surface) | |
surface.surface = C.SDL_DisplayFormat(surface.surface) | |
} | |
func (event *Event) PollEvent() int { | |
return 1 | |
} |
This file contains hidden or 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
#include "SDL/SDL.h" | |
//SDL_Init flags | |
enum { | |
$INIT_TIMER = SDL_INIT_TIMER, | |
$INIT_AUDIO = SDL_INIT_AUDIO, | |
$INIT_VIDEO = SDL_INIT_VIDEO, | |
$INIT_CDROM = SDL_INIT_CDROM, | |
$INIT_JOYSTICK = SDL_INIT_JOYSTICK, | |
$INIT_NOPARACHUTE = SDL_INIT_NOPARACHUTE, | |
$INIT_EVENTTHREAD = SDL_INIT_EVENTTHREAD, | |
$INIT_EVERYTHING = SDL_INIT_EVERYTHING | |
}; | |
//SDL_Surface flags | |
enum { | |
// Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() | |
$SWSURFACE = SDL_SWSURFACE, | |
$HWSURFACE = SDL_HWSURFACE, | |
$ASYNCBLIT = SDL_ASYNCBLIT, | |
// Available for SDL_SetVideoMode() | |
$ANYFORMAT = SDL_ANYFORMAT, | |
$HWPALETTE = SDL_HWPALETTE, | |
$DOUBLEBUF = SDL_DOUBLEBUF, | |
$FULLSCREEN = SDL_FULLSCREEN, | |
$OPENGL = SDL_OPENGL, | |
$OPENGLBLIT = SDL_OPENGLBLIT, | |
$RESIZABLE = SDL_RESIZABLE, | |
$NOFRAME = SDL_NOFRAME, | |
// Used internally (read-only) | |
$HWACCEL = SDL_HWACCEL, | |
$SRCCOLORKEY = SDL_SRCCOLORKEY, | |
$RLEACCELOK = SDL_RLEACCELOK, | |
$RLEACCEL = SDL_RLEACCEL, | |
$SRCALPHA = SDL_SRCALPHA, | |
$PREALLOC = SDL_PREALLOC | |
}; | |
//SDL_Event constants | |
enum { | |
$QUIT = SDL_QUIT | |
}; |
This file contains hidden or 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
// godefs -g sdl sdl_constants.c | |
// MACHINE GENERATED - DO NOT EDIT. | |
package sdl | |
// Constants | |
const ( | |
INIT_TIMER = 0x1 | |
INIT_AUDIO = 0x10 | |
INIT_VIDEO = 0x20 | |
INIT_CDROM = 0x100 | |
INIT_JOYSTICK = 0x200 | |
INIT_NOPARACHUTE = 0x100000 | |
INIT_EVENTTHREAD = 0x1000000 | |
INIT_EVERYTHING = 0xffff | |
SWSURFACE = 0 | |
HWSURFACE = 0x1 | |
ASYNCBLIT = 0x4 | |
ANYFORMAT = 0x10000000 | |
HWPALETTE = 0x20000000 | |
DOUBLEBUF = 0x40000000 | |
FULLSCREEN = 0x80000000 | |
OPENGL = 0x2 | |
OPENGLBLIT = 0xa | |
RESIZABLE = 0x10 | |
NOFRAME = 0x20 | |
HWACCEL = 0x100 | |
SRCCOLORKEY = 0x1000 | |
RLEACCELOK = 0x2000 | |
RLEACCEL = 0x4000 | |
SRCALPHA = 0x10000 | |
PREALLOC = 0x1000000 | |
QUIT = 0xc | |
) | |
// Types |
This file contains hidden or 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
package sdl | |
type Rect struct { | |
X int16 | |
Y int16 | |
W uint16 | |
H uint16 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment