Example #1
0
func ColorKeyToSDL(_color uint32) sdl.Color {
	var sdlcolor sdl.Color
	sdlcolor.R = (uint8)(_color >> 16)
	sdlcolor.G = (uint8)(_color >> 8)
	sdlcolor.B = (uint8)(_color)
	return sdlcolor
}
Example #2
0
func (f *Font) setupTextRendering(color [3]byte, txt string) (gl.GLuint, *sdl.Surface, *sdl.Surface, *sdl.Surface, int, int) {

	//
	var texture gl.GLuint

	/* Use SDL_TTF to render our text */
	var col sdl.Color
	col.R = color[0]
	col.G = color[1]
	col.B = color[2]

	// get surface with text
	initial := ttf.RenderText_Blended(f.font, txt, col)

	/* Convert the rendered text to a known format */
	w := next_p2(int(initial.W))
	h := next_p2(int(initial.H))

	intermediarya := sdl.CreateRGBSurface(0, w, h, 32,
		0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000)

	var rr *sdl.Rect = nil
	intermediarya.Blit(rr, initial, rr)

	intermediary := intermediarya.DisplayFormatAlpha()

	/* Tell GL about our new texture */
	gl.GenTextures(1, &texture)
	gl.BindTexture(gl.TEXTURE_2D, texture)
	gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.GLsizei(w), gl.GLsizei(h), 0, gl.BGRA,
		gl.UNSIGNED_BYTE, unsafe.Pointer(intermediary.Pixels))

	gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)

	/* GL_NEAREST looks horrible, if scaled... */
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	/* prepare to render our texture */
	gl.Enable(gl.TEXTURE_2D)

	gl.BindTexture(gl.TEXTURE_2D, texture)
	gl.Color4f(1.0, 1.0, 1.0, 1.0)

	gl.Enable(gl.BLEND)
	//	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR) // TODO : MAke real alpha work!

	return texture, initial, intermediarya, intermediary, w, h
}