Ejemplo n.º 1
0
// Bind binds the texture
func (t *Texture) Bind(coordType CoordType) {
	// ensureGlContext()

	if t != nil && t.t != 0 {
		// Bind the texture
		t.t.Bind(gl.TEXTURE_2D)

		// Check if we need to define a special texture matrix
		if coordType == CoordPixels || t.pixelsFlipped {
			matrix := [16]float32{1, 0, 0, 0,
				0, 1, 0, 0,
				0, 0, 1, 0,
				0, 0, 0, 1}

			// If non-normalized coordinates (= pixels) are requested, we need to
			// setup scale factors that convert the range [0 .. size] to [0 .. 1]
			if coordType == CoordPixels {
				matrix[0] = 1.0 / t.size.X
				matrix[5] = 1.0 / t.size.Y
			}

			// If pixels are flipped we must invert the Y axis
			if t.pixelsFlipped {
				matrix[5] = -matrix[5]
				matrix[13] = 1.0
			}

			// Load the matrix
			gl.MatrixMode(gl.TEXTURE)
			gl.LoadMatrixf(&matrix)

			// Go back to model-view mode (sf::RenderTarget relies on it)
			gl.MatrixMode(gl.MODELVIEW)
		}
	} else {
		// Bind no texture
		gl.Texture(0).Unbind(gl.TEXTURE_2D)

		// Reset the texture matrix
		gl.MatrixMode(gl.TEXTURE)
		gl.LoadIdentity()

		// Go back to model-view mode (sf::RenderTarget relies on it)
		gl.MatrixMode(gl.MODELVIEW)
	}
}
Ejemplo n.º 2
0
func (r *RenderTarget) applyCurrentView() {
	// Set the viewport
	viewport := r.Viewport(r.view)
	top := r.Size.Y - (viewport.Top + viewport.H)
	gl.Viewport(int(viewport.Left), int(top), int(viewport.W), int(viewport.H))

	mat := r.view.Transform().Matrix

	// Set the projection matrix
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadMatrixf(&mat)

	// Go back to model-view mode
	gl.MatrixMode(gl.MODELVIEW)

	r.viewChanged = false
}
Ejemplo n.º 3
0
func (r *RenderTarget) applyTransform(transform Transform) {
	// No need to call glMatrixMode(gl.MODELVIEW), it is always the
	// current mode (for optimization purpose, since it's the most used)
	gl.LoadMatrixf(&transform.Matrix)
}