func createMainWindow() { var err error var mainWindow *sdl.Window gc := gamecontext.GContext gc.WindowWidth = 800 gc.WindowHeight = 600 mainWindow, err = sdl.CreateWindow("Eggdrop!", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, int(gc.WindowWidth), int(gc.WindowHeight), sdl.WINDOW_SHOWN) if err != nil { panic(err) } gc.MainSurface, err = mainWindow.GetSurface() if err != nil { panic(err) } gc.PixelFormatEnum, err = mainWindow.GetPixelFormat() if err != nil { panic(err) } gc.PixelFormat, err = sdl.AllocFormat(uint(gc.PixelFormatEnum)) // TODO why the cast? Seems to work? if err != nil { panic(err) } gc.MainWindow = mainWindow }
// MakeFillSurfaceAlpha makes a new rectangular surface and fills with with RGBA func MakeFillSurfaceAlpha(width, height int32, red, green, blue, alpha uint8) (*sdl.Surface, error) { pf, err := sdl.AllocFormat(sdl.PIXELFORMAT_RGBA8888) if err != nil { return nil, err } color := sdl.MapRGBA(pf, red, green, blue, alpha) surface, err := sdl.CreateRGBSurface(0, width, height, 32, pf.Rmask, pf.Gmask, pf.Bmask, pf.Amask) if err != nil { return nil, err } surface.FillRect(&sdl.Rect{X: 0, Y: 0, W: width, H: height}, color) return surface, nil }