示例#1
0
文件: graf.go 项目: pwaller/mema
func Init() {
	//gl.Enable(gl.DEPTH_TEST)

	var tmpmaxa []float32 = []float32{0}

	gl.GetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, tmpmaxa)
	MaxAnisotropy = tmpmaxa[0]
	log.Print("MaxAnisotropy: ", MaxAnisotropy)

	// Anti-aliasing
	gl.Enable(gl.LINE_SMOOTH)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	//gl.BlendFunc(gl.SRC_ALPHA, gl.DST_ALPHA)
	//gl.BlendFunc(gl.SRC_ALPHA_SATURATE, gl.ONE)
	gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)
	gl.Hint(gl.GENERATE_MIPMAP_HINT, gl.NICEST)

	extensions := gl.GetString(gl.EXTENSIONS)
	if !strings.Contains(extensions, "GL_ARB_framebuffer_object") {
		log.Panic("No FBO support :-(")
	}
}
示例#2
0
文件: font.go 项目: nobonobo/gltext
// Printf draws the given string at the specified coordinates.
// It expects the string to be a single line. Line breaks are not
// handled as line breaks and are rendered as glyphs.
//
// In order to render multi-line text, it is up to the caller to split
// the text up into individual lines of adequate length and then call
// this method for each line seperately.
func (f *Font) Printf(x, y float32, fs string, argv ...interface{}) error {
	indices := []rune(fmt.Sprintf(fs, argv...))

	if len(indices) == 0 {
		return nil
	}

	// Runes form display list indices.
	// For this purpose, they need to be offset by -FontConfig.Low
	low := f.Config.Low
	for i := range indices {
		indices[i] -= low
	}

	var vp [4]int32
	gl.GetIntegerv(gl.VIEWPORT, vp[:])

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(float64(vp[0]), float64(vp[2]), float64(vp[1]), float64(vp[3]), 0, 1)
	gl.PopAttrib()

	gl.PushAttrib(gl.LIST_BIT | gl.CURRENT_BIT | gl.ENABLE_BIT | gl.TRANSFORM_BIT)
	{
		gl.MatrixMode(gl.MODELVIEW)
		gl.Disable(gl.LIGHTING)
		gl.Disable(gl.DEPTH_TEST)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.TEXTURE_2D)

		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		f.Texture.Bind(gl.TEXTURE_2D)

		var mv [16]float32
		gl.GetFloatv(gl.MODELVIEW_MATRIX, mv[:])

		gl.PushMatrix()
		{
			gl.LoadIdentity()

			mgw := float32(f.maxGlyphWidth)
			mgh := float32(f.maxGlyphHeight)

			switch f.Config.Dir {
			case LeftToRight, TopToBottom:
				gl.Translatef(x, float32(vp[3])-y-mgh, 0)
			case RightToLeft:
				gl.Translatef(x-mgw, float32(vp[3])-y-mgh, 0)
			}

			gl.MultMatrixf(&mv)
			gl.CallLists(len(indices), gl.UNSIGNED_INT, indices)
		}
		gl.PopMatrix()
		f.Texture.Unbind(gl.TEXTURE_2D)
	}
	gl.PopAttrib()

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.PopAttrib()
	return glh.CheckGLError()
}