Esempio n. 1
0
//=================================
//Initialize Lortet
//=================================
func main() {
	//INIT SDL
	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}

	screen = sdl.SetVideoMode(SCREENWIDTH, SCREENHEIGHT, BPP, sdl.SWSURFACE)
	if screen == nil {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("MapMaker", "")

	if ttf.Init() != 0 {
		panic(sdl.GetError())
	}

	font = ttf.OpenFont("../Fontin Sans.otf", 15)

	if font == nil {
		panic(sdl.GetError())
	}

	objects = ScreenObjects{}

	//Load Media
	IM = LoadImages()

	MainLoop()

	ExitProgram()
}
func main() {
	if sdl.Init(sdl.INIT_VIDEO) < 0 {
		panic("Video initialization failed: " + sdl.GetError())
	}

	if sdl.EnableKeyRepeat(100, 25) != 0 {
		panic("Setting keyboard repeat failed: " + sdl.GetError())
	}

	videoFlags := sdl.OPENGL    // Enable OpenGL in SDL
	videoFlags |= sdl.DOUBLEBUF // Enable double buffering
	videoFlags |= sdl.HWPALETTE // Store the palette in hardware
	// FIXME: this causes segfault.
	// videoFlags |= sdl.RESIZABLE // Enable window resizing

	surface = sdl.SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, uint32(videoFlags))

	if surface == nil {
		panic("Video mode set failed: " + sdl.GetError())
	}

	sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
	initGL()
	resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT)

	SetupWorld("data/world.txt")

	// wait for events
	running := true
	isActive := true
	for running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.ActiveEvent:
				isActive = e.Gain != 0
			case *sdl.ResizeEvent:
				width, height := int(e.W), int(e.H)
				surface = sdl.SetVideoMode(width, height, SCREEN_BPP, uint32(videoFlags))
				if surface == nil {
					fmt.Println("Could not get a surface after resize:", sdl.GetError())
					Quit(1)
				}
				resizeWindow(width, height)
			case *sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					handleKeyPress(e.Keysym)
				}
			case *sdl.QuitEvent:
				running = false
			}
		}

		// draw the scene
		if isActive {
			drawGLScene(sector1)
		}
	}
}
func main() {
	if sdl.Init(sdl.INIT_VIDEO) != 0 {
		fmt.Println(sdl.GetError())
		return
	}
	defer sdl.Quit()

	if sdl.SetVideoMode(200, 200, 32, 0) == nil {
		fmt.Println(sdl.GetError())
		return
	}

	for e := new(sdl.Event); e.Wait() && e.Type != sdl.QUIT; {
	}
}
Esempio n. 4
0
func loadMusic(path string) *mixer.Music {
	load := mixer.LoadMUS(path)
	if load == nil {
		panic(sdl.GetError())
	}
	return load
}
Esempio n. 5
0
func loadSound(path string) *mixer.Chunk {
	load := mixer.LoadWAV(path)
	if load == nil {
		panic(sdl.GetError())
	}
	return load
}
Esempio n. 6
0
//=================================
//Initialize Lortet
//=================================
func main() {
	//INIT SDL
	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}

	screen = sdl.SetVideoMode(SCREENWIDTH, SCREENHEIGHT, BPP, sdl.SWSURFACE)
	if screen == nil {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("KAGE!", "")

	/*if ttf.Init() != 0 {
	    panic(sdl.GetError())
	}

	font := ttf.OpenFont("Fontin Sans.otf", 15)

	if font == nil {
		panic(sdl.GetError())
	}*/

	//debug = ttf.RenderText_Blended(font, "Test (with music)", sdl.Color{255, 255, 255, 0})

	if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT,
		mixer.DEFAULT_CHANNELS, 1096) != 0 {
		panic(sdl.GetError())
	}

	sdl.ShowCursor(sdl.DISABLE)

	//Load Media
	IM = LoadImages()
	MU = LoadSound()

	//Load Maps
	baner := NewJSONlevel("levels")
	for _, v := range baner {
		MapList = append(MapList, v.Create())
	}

	MainLoop()

	ExitProgram()
}
Esempio n. 7
0
func loadImage(path string) *sdl.Surface {
	loaded := sdl.Load(path)

	if loaded == nil {
		panic(sdl.GetError())
	}
	defer loaded.Free()
	return sdl.DisplayFormat(loaded)
}
Esempio n. 8
0
func loadImage(name string) *sdl.Surface {
	image := sdl.Load(name)

	if image == nil {
		panic(sdl.GetError())
	}

	return image

}
Esempio n. 9
0
func main() {

	flag.Parse()

	var done bool
	var keys []uint8

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(640, 480, 16, sdl.OPENGL|sdl.RESIZABLE)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
	}

	sdl.WM_SetCaption("Gears", "gears")

	init_()
	reshape(int(screen.W), int(screen.H))
	done = false
	for !done {
		var event sdl.Event

		idle()
		for event.Poll() {
			switch event.Type {
			case sdl.VIDEORESIZE:
				screen = sdl.SetVideoMode(int(event.Resize().W), int(event.Resize().H), 16,
					sdl.OPENGL|sdl.RESIZABLE)
				if screen != nil {
					reshape(int(screen.W), int(screen.H))
				} else {
					panic("we couldn't set the new video mode??")
				}
				break

			case sdl.QUIT:
				done = true
				break
			}
		}
		keys = sdl.GetKeyState()

		handleKeyPress(keys)
		if keys[sdl.K_ESCAPE] != 0 {
			done = true
		}

		draw()
	}
	sdl.Quit()
	return

}
// Load bitmap from path as GL texture
func LoadGLTexture(path string) {
	image := sdl.Load(path)
	if image == nil {
		panic(sdl.GetError())
	}

	// Check that the image's width is a power of 2
	if image.W&(image.W-1) != 0 {
		fmt.Println("warning:", path, "has a width that is not a power of 2")
	}

	// Also check if the height is a power of 2
	if image.H&(image.H-1) != 0 {
		fmt.Println("warning:", path, "has an height that is not a power of 2")
	}

	// get the number of channels in the SDL surface
	nOfColors := image.Format.BytesPerPixel
	var textureFormat gl.GLenum

	if nOfColors == 4 { // contains alpha channel
		if image.Format.Rmask == 0x000000ff {
			textureFormat = gl.RGBA
		} else {
			textureFormat = gl.BGRA
		}
	} else if nOfColors == 3 { // no alpha channel
		if image.Format.Rmask == 0x000000ff {
			textureFormat = gl.RGB
		} else {
			textureFormat = gl.BGR
		}
	} else {
		fmt.Println("warning:", path, "is not truecolor, this will probably break")
	}

	texture = gl.GenTexture()

	// Typical texture generation using data from the bitmap
	gl.BindTexture(gl.TEXTURE_2D, uint(texture))

	// Generate the texture
	gl.TexImage2D(gl.TEXTURE_2D, 0, int(image.Format.BytesPerPixel),
		int(image.W), int(image.H),
		0, textureFormat, gl.UNSIGNED_BYTE, image.Pixels,
	)

	// linear filtering
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	// free up memory we have used.
	image.Free()
}
Esempio n. 11
0
func resize(width int, height int) {
	screen = sdl.SetVideoMode(width, height, 32, sdl.RESIZABLE)
	if screen == nil {
		panic(sdl.GetError())
	}

	gridSizePixels := min(width, height)
	cellSize = gridSizePixels / gridSize
	offsetX = (width - gridSizePixels) / 2
	offsetY = (height - gridSizePixels) / 2
}
Esempio n. 12
0
func main() {

	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}

	var screen = sdl.SetVideoMode(640, 480, 32, 0)

	if screen == nil {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("Template", "")

	running := true

	for running {

		e := &sdl.Event{}

		for e.Poll() {
			switch e.Type {
			case sdl.QUIT:
				running = false
				break
			default:
			}
		}

		screen.FillRect(nil, 0x000000)

		//screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil)

		screen.Flip()
		sdl.Delay(25)

	}

	sdl.Quit()

}
Esempio n. 13
0
func initinc() error {
	if initnum == 0 {
		errn := sdl.Init(sdl.INIT_VIDEO)
		if errn < 0 {
			return errors.New(sdl.GetError())
		}
	}

	initnum++

	return nil
}
Esempio n. 14
0
func NewFont(_file string, _size int) *PU_Font {
	sdlfont := sdl.LoadFont(_file, _size)
	if sdlfont == nil {
		fmt.Printf("Error loading Font: %v", sdl.GetError())
	}
	f := &PU_Font{font: sdlfont,
		fontmap: make(map[uint32]map[uint16]*PU_Image),
		color:   &sdl.Color{255, 255, 255, 255},
		alpha:   255,
		size:    _size}
	f.Build()
	return f
}
Esempio n. 15
0
//Load font from file and specify font size (each font-size needs a seperate font instance)
func NewFont(_file string, _size int) *Font {
	sdlfont := sdl.LoadFont(_file, _size)
	if sdlfont == nil {
		fmt.Printf("Go2D Error: Loading Font: %v", sdl.GetError())
	}
	f := &Font{font: sdlfont,
		fontmap: make(map[uint32]map[uint16]*Image),
		color:   &sdl.Color{255, 255, 255, 255},
		alpha:   255,
		size:    _size}
	addResource(f)
	f.build()
	return f
}
Esempio n. 16
0
func main() {
	fmt.Println("loaded", len(blokus.Tiles), "shapes")
	blokus.Board[2][4] = blokus.Red
	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}
	resize(640, 480)
	sdl.WM_SetCaption("Blokus", "")

	for running {
		e := &sdl.Event{}

		for e.Poll() {
			switch e.Type {
			case sdl.QUIT:
				running = false
			case sdl.KEYDOWN:
				keyDown(e.Keyboard())
			case sdl.KEYUP:
				keyUp(e.Keyboard())
			case sdl.MOUSEBUTTONDOWN:
				mouseDown(e.MouseButton())
			case sdl.VIDEORESIZE:
				r := e.Resize()
				resize(int(r.W), int(r.H))
			default:
			}
			if !running {
				break
			}
		}

		draw()

		sdl.Delay(25)
	}

	sdl.Quit()
}
Esempio n. 17
0
func NewWindow(w, h, bpp int, flags uint32) (gui.Window, error) {
	win := new(window)

	err := initinc()
	if err != nil {
		return nil, err
	}

	win.screen = sdl.SetVideoMode(w, h, bpp, flags)
	if win.screen == nil {
		return nil, errors.New(sdl.GetError())
	}

	win.ec = make(chan interface{})
	win.events = true
	go win.eventLoop()

	runtime.SetFinalizer(win, func(subwin *window) {
		subwin.Close()
	})

	return win, nil
}
func LoadImage(path string) (image *sdl.Surface, format gl.GLenum) {
	image = sdl.Load(path)
	if image == nil {
		panic(sdl.GetError())
	}

	// Check that the image's width is a power of 2
	if image.W&(image.W-1) != 0 {
		fmt.Println("warning:", path, "has a width that is not a power of 2")
	}

	// Also check if the height is a power of 2
	if image.H&(image.H-1) != 0 {
		fmt.Println("warning:", path, "has an height that is not a power of 2")
	}

	// get the number of channels in the SDL surface
	nOfColors := image.Format.BytesPerPixel
	if nOfColors == 4 { // contains alpha channel
		if image.Format.Rmask == 0x000000ff {
			format = gl.RGBA
		} else {
			format = gl.BGRA
		}
	} else if nOfColors == 3 { // no alpha channel
		if image.Format.Rmask == 0x000000ff {
			format = gl.RGB
		} else {
			format = gl.BGR
		}
	} else {
		fmt.Println("warning:", path, "is not truecolor, this will probably break")
	}

	return image, format
}
Esempio n. 19
0
func main() {

	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}

	if ttf.Init() != 0 {
		panic(sdl.GetError())
	}

	if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT,
		mixer.DEFAULT_CHANNELS, 4096) != 0 {
		panic(sdl.GetError())
	}

	var screen = sdl.SetVideoMode(640, 480, 32, sdl.RESIZABLE)

	if screen == nil {
		panic(sdl.GetError())
	}

	var video_info = sdl.GetVideoInfo()

	println("HW_available = ", video_info.HW_available)
	println("WM_available = ", video_info.WM_available)
	println("Video_mem = ", video_info.Video_mem, "kb")

	sdl.EnableUNICODE(1)

	sdl.WM_SetCaption("Go-SDL SDL Test", "")

	image := sdl.Load("test.png")

	if image == nil {
		panic(sdl.GetError())
	}

	sdl.WM_SetIcon(image, nil)

	running := true

	font := ttf.OpenFont("Fontin Sans.otf", 72)

	if font == nil {
		panic(sdl.GetError())
	}

	font.SetStyle(ttf.STYLE_UNDERLINE)
	white := sdl.Color{255, 255, 255, 0}
	text := ttf.RenderText_Blended(font, "Test (with music)", white)
	music := mixer.LoadMUS("test.ogg")
	sound := mixer.LoadWAV("sound.ogg")

	if music == nil || sound == nil {
		panic(sdl.GetError())
	}

	music.PlayMusic(-1)

	if sdl.GetKeyName(270) != "[+]" {
		panic("GetKeyName broken")
	}

	worm_in := make(chan Point)
	draw := make(chan Point, 64)

	var out chan Point
	var in chan Point

	out = worm_in

	in = out
	out = make(chan Point)
	go worm(in, out, draw)

	for running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.QuitEvent:
				running = false
				break
			case *sdl.KeyboardEvent:
				println("")
				println(e.Keysym.Sym, ": ", sdl.GetKeyName(sdl.Key(e.Keysym.Sym)))

				if e.Keysym.Sym == 27 {
					running = false
				}

				fmt.Printf("%04x ", e.Type)

				for i := 0; i < len(e.Pad0); i++ {
					fmt.Printf("%02x ", e.Pad0[i])
				}
				println()

				fmt.Printf("Type: %02x Which: %02x State: %02x Pad: %02x\n", e.Type, e.Which, e.State, e.Pad0[0])
				fmt.Printf("Scancode: %02x Sym: %08x Mod: %04x Unicode: %04x\n", e.Keysym.Scancode, e.Keysym.Sym, e.Keysym.Mod, e.Keysym.Unicode)
			case *sdl.MouseButtonEvent:
				if e.Type == sdl.MOUSEBUTTONDOWN {
					println("Click:", e.X, e.Y)
					in = out
					out = make(chan Point)
					go worm(in, out, draw)
					sound.PlayChannel(-1, 0)
				}
			case *sdl.ResizeEvent:
				println("resize screen ", e.W, e.H)

				screen = sdl.SetVideoMode(int(e.W), int(e.H), 32, sdl.RESIZABLE)

				if screen == nil {
					panic(sdl.GetError())
				}
			}
		}

		screen.FillRect(nil, 0x302019)
		screen.Blit(&sdl.Rect{0, 0, 0, 0}, text, nil)

		loop := true

		for loop {

			select {
			case p := <-draw:
				screen.Blit(&sdl.Rect{int16(p.x), int16(p.y), 0, 0}, image, nil)
			case <-out:
			default:
				loop = false
			}

		}

		var p Point
		sdl.GetMouseState(&p.x, &p.y)
		worm_in <- p

		screen.Flip()
		sdl.Delay(25)
	}

	image.Free()
	music.Free()
	font.Close()

	ttf.Quit()
	sdl.Quit()
}
func main() {
	// Initialize SDL
	if sdl.Init(sdl.INIT_VIDEO) < 0 {
		panic("Video initialization failed: " + sdl.GetError())
	}

	// flags to pass to sdl.SetVideoMode
	videoFlags := sdl.OPENGL    // Enable OpenGL in SDL
	videoFlags |= sdl.DOUBLEBUF // Enable double buffering
	videoFlags |= sdl.HWPALETTE // Store the palette in hardware
	// FIXME: this causes segfault.
	// videoFlags |= sdl.RESIZABLE // Enable window resizing

	// get a SDL surface
	surface = sdl.SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, uint32(videoFlags))

	// verify there is a surface
	if surface == nil {
		panic("Video mode set failed: " + sdl.GetError())
		Quit(1)
	}

	// When this function is finished, clean up and exit.
	defer Quit(0)

	// Sets up OpenGL double buffering
	sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)

	// Execute everything needed for OpenGL
	initGL()

	// Resize the initial window
	resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT)

	// wait for events
	running := true
	isActive := true
	for running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.ActiveEvent:
				isActive = e.Gain != 0
			case *sdl.ResizeEvent:
				width, height := int(e.W), int(e.H)
				surface = sdl.SetVideoMode(width, height, SCREEN_BPP, uint32(videoFlags))

				if surface == nil {
					fmt.Println("Could not get a surface after resize:", sdl.GetError())
					Quit(1)
				}
				resizeWindow(width, height)
			case *sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					handleKeyPress(e.Keysym)
				}
			case *sdl.QuitEvent:
				running = false
			}
		}

		// draw the scene
		if isActive {
			drawGLScene()
		}
	}
}
Esempio n. 21
0
func main() {

	filename = flag.String("file", "testbed/data/dude.dat", "enter filename path")
	cx = flag.Int("cx", 300, "enter x-coordinate center")
	cy = flag.Int("cy", 500, "enter y-coordinate center")
	zoom = flag.Float64("zoom", 2, "enter zoom")

	flag.Parse()

	fmt.Println("opening...", *filename)
	f, err := os.Open(*filename)
	if f == nil {
		fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", *filename, err)
		os.Exit(1)
	}

	d, _ := ioutil.ReadAll(f)
	line := strings.SplitAfter(string(d), "\n")

	j := 0
	for i := 0; i < len(line); i++ {
		if len(line[i]) <= 2 {
			break
		}
		j++
	}

	var polyline = make(p2t.PointArray, j)
	for i := 0; i < j; i++ {
		line[i] = strings.TrimRight(line[i], "\r\n")
		num := strings.Split(line[i], " ")
		n1, err1 := strconv.Atof64(num[0])
		n2, err2 := strconv.Atof64(num[1])
		if err1 != nil || err2 != nil {
			fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", *filename, err)
			os.Exit(1)
		}
		polyline[i] = &p2t.Point{X: n1, Y: n2}
	}

	f.Close()

	left = -Width / float64(*zoom)
	right = Width / float64(*zoom)
	bottom = -Height / float64(*zoom)
	top = Height / float64(*zoom)

	last_time := time.Nanoseconds()

	p2t.Init(polyline)
	var triangles p2t.TriArray = p2t.Triangulate()

	dt := time.Nanoseconds() - last_time
	fmt.Printf("Elapsed time : %f ms\n", float64(dt)*1e-6)

	//var mesh p2t.TriArray = p2t.Mesh()

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(Width, Height, 16, sdl.OPENGL|sdl.RESIZABLE)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set GL video mode: " + sdl.GetError() + "\n")
	}

	sdl.WM_SetCaption("Pol2tri - testbed", "poly2tri")

	if gl.Init() != 0 {
		panic("gl error")
	}

	initGL()

	done := false
	for !done {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.ResizeEvent:
				re := e.(*sdl.ResizeEvent)
				screen = sdl.SetVideoMode(int(re.W), int(re.H), 16,
					sdl.OPENGL|sdl.RESIZABLE)
				if screen != nil {
					reshape(int(screen.W), int(screen.H))
				} else {
					panic("we couldn't set the new video mode??")
				}
				break

			case *sdl.QuitEvent:
				done = true
				break
			}
		}
		keys := sdl.GetKeyState()

		if keys[sdl.K_ESCAPE] != 0 {
			done = true
		}
		resetZoom()
		draw(triangles)
	}
	sdl.Quit()
	return

}
Esempio n. 22
0
func main() {

	flag.Parse()

	var done bool
	var keys []uint8

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
	}

	sdl.WM_SetCaption("Gears", "gears")

	init_()
	reshape(int(screen.W), int(screen.H))
	done = false
	for !done {
		var event sdl.Event

		idle()
		for event.Poll() {
			switch event.Type {
			case sdl.VIDEORESIZE:
				screen = sdl.SetVideoMode(int(event.Resize().W), int(event.Resize().H), 16,
					sdl.OPENGL|sdl.RESIZABLE)
				if screen != nil {
					reshape(int(screen.W), int(screen.H))
				} else {
					panic("we couldn't set the new video mode??")
				}
				break

			case sdl.QUIT:
				done = true
				break
			}
		}
		keys = sdl.GetKeyState()

		if keys[sdl.K_ESCAPE] != 0 {
			done = true
		}
		if keys[sdl.K_UP] != 0 {
			view_rotx += 5.0
		}
		if keys[sdl.K_DOWN] != 0 {
			view_rotx -= 5.0
		}
		if keys[sdl.K_LEFT] != 0 {
			view_roty += 5.0
		}
		if keys[sdl.K_RIGHT] != 0 {
			view_roty -= 5.0
		}
		if keys[sdl.K_z] != 0 {
			if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 {
				view_rotz -= 5.0
			} else {
				view_rotz += 5.0
			}
		}

		draw()
	}
	sdl.Quit()
	return

}
// load in bitmap as a GL texture
func LoadGLTextures(path string) {
	image := sdl.Load(path)
	if image == nil {
		panic(sdl.GetError())
	}

	// Check that the image's width is a power of 2
	if image.W&(image.W-1) != 0 {
		fmt.Println("warning:", path, "has a width that is not a power of 2")
	}

	// Also check if the height is a power of 2
	if image.H&(image.H-1) != 0 {
		fmt.Println("warning:", path, "has an height that is not a power of 2")
	}

	// get the number of channels in the SDL surface
	nOfColors := image.Format.BytesPerPixel
	var textureFormat gl.GLenum

	if nOfColors == 4 { // contains alpha channel
		if image.Format.Rmask == 0x000000ff {
			textureFormat = gl.RGBA
		} else {
			textureFormat = gl.BGRA
		}
	} else if nOfColors == 3 { // no alpha channel
		if image.Format.Rmask == 0x000000ff {
			textureFormat = gl.RGB
		} else {
			textureFormat = gl.BGR
		}
	} else {
		fmt.Println("warning:", path, "is not truecolor, this will probably break")
	}

	// Create the textures
	gl.GenTextures(textures[:])

	// First texture
	gl.BindTexture(gl.TEXTURE_2D, uint(textures[0]))
	gl.TexImage2D(
		gl.TEXTURE_2D,
		0,
		3,
		int(image.W),
		int(image.H),
		0,
		textureFormat,
		gl.UNSIGNED_BYTE,
		image.Pixels,
	)

	// linear filtering
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	// Second texture
	gl.BindTexture(gl.TEXTURE_2D, uint(textures[1]))
	gl.TexImage2D(gl.TEXTURE_2D, 0,
		3,
		int(image.W),
		int(image.H),
		0, textureFormat, gl.UNSIGNED_BYTE,
		image.Pixels,
	)

	// Mipmapped filtering
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	// Third texture
	gl.BindTexture(gl.TEXTURE_2D, uint(textures[2]))
	gl.TexImage2D(gl.TEXTURE_2D, 0,
		3,
		int(image.W),
		int(image.H),
		0, textureFormat, gl.UNSIGNED_BYTE,
		image.Pixels,
	)

	// Mipmapped filtering
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	glu.Build2DMipmaps(
		gl.TEXTURE_2D,
		3,
		int(image.W),
		int(image.H),
		textureFormat,
		image.Pixels,
	)
}