예제 #1
0
파일: util.go 프로젝트: jasonrpowers/glh
// Returns x, y in window co-ordinates at 0 in the z direction
func ProjToWindow(x, y float64) (float64, float64) {
	var projmat, modelmat [16]float64
	var viewport [4]int32

	gl.GetDoublev(gl.PROJECTION_MATRIX, projmat[:])
	gl.GetDoublev(gl.MODELVIEW_MATRIX, modelmat[:])
	gl.GetIntegerv(gl.VIEWPORT, viewport[:])

	px, py, _ := glu.Project(float64(x), float64(y), 0,
		&modelmat, &projmat, &viewport)

	//return int(px), int(viewport[3]) - int(py)
	return px, float64(viewport[3]) - py
}
예제 #2
0
파일: util.go 프로젝트: jasonrpowers/glh
// Returns x, y in window co-ordinates at 0 in the z direction
func WindowToProj(x, y int) (float64, float64) {
	var projmat, modelmat [16]float64
	var viewport [4]int32

	gl.GetDoublev(gl.PROJECTION_MATRIX, projmat[:])
	gl.GetDoublev(gl.MODELVIEW_MATRIX, modelmat[:])

	gl.GetIntegerv(gl.VIEWPORT, viewport[:])
	// Need to convert so that y is at lower left
	y = int(viewport[3]) - y

	px, py, _ := glu.UnProject(float64(x), float64(y), 0,
		&modelmat, &projmat, &viewport)

	return px, py
}
예제 #3
0
파일: main.go 프로젝트: srm88/blocks
func redraw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	var viewport [4]int32
	gl.GetIntegerv(gl.VIEWPORT, viewport[:4])
	aspect := float64(viewport[2]) / float64(viewport[3])
	glu.Perspective(60, aspect, 1, 100)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(POV.X, POV.Y, POV.Z)
	gl.Rotatef(POV.Pitch, 1, 0, 0)
	gl.Rotatef(POV.Yaw, 0, 1, 0)
	gl.Rotatef(POV.Roll, 0, 0, 1)
	for x, row := range World {
		for z, block := range row {
			drawBlock(translateCoordinates(x, 0, z), block)
			if x == CursorX && z == CursorZ {
				drawCursor()
			}
		}
	}
}
예제 #4
0
파일: util.go 프로젝트: jasonrpowers/glh
// Returns w, h of viewport
func GetViewportWH() (int, int) {
	var viewport [4]int32
	gl.GetIntegerv(gl.VIEWPORT, viewport[:])
	return int(viewport[2]), int(viewport[3])
}
예제 #5
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()
}
예제 #6
0
func getMaxTextureSize() int {
	maxTexSize := make([]int32, 1)
	gl.GetIntegerv(gl.MAX_TEXTURE_SIZE, maxTexSize)
	return int(maxTexSize[0])
}