Example #1
0
func (self *Texture) setupParams() {
	self.tex.Bind(gl.TEXTURE_2D)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

	if self.Setup.Mipmaps {
		gl.GenerateMipmap(gl.TEXTURE_2D)
	}

	switch self.Setup.Filtering {
	case NEAREST:
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
		break
	case LINEAR:
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
		break
	case TRILINEAR:
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR_MIPMAP_LINEAR)
		break
	}

	gl.BindTexture(gl.TEXTURE_2D, 0)
}
Example #2
0
func RenderTexturedRect(cam *Camera, m *v.Matrix4, sizeX, sizeY float32, t *Texture) {
	cam.LoadProjection()
	cam.LoadModelview(m)

	gl.Enable(gl.TEXTURE_2D)
	t.tex.Bind(gl.TEXTURE_2D)

	gl.Color4ub(255, 255, 255, 255)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-sizeX, -sizeY, 0)

	gl.TexCoord2f(1, 1)
	gl.Vertex3f(sizeX, -sizeY, 0)

	gl.TexCoord2f(1, 0)
	gl.Vertex3f(sizeX, sizeY, 0)

	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-sizeX, sizeY, 0)
	gl.End()

	gl.Disable(gl.TEXTURE_2D)
	gl.BindTexture(gl.TEXTURE_2D, 0)
}
Example #3
0
func (self *Texture) LoadData(data []uint8) {
	self.tex.Bind(gl.TEXTURE_2D)

	if data == nil {
		gl.TexImage2D(gl.TEXTURE_2D, 0, self.Setup.InternalFormat,
			self.Width, self.Height, 0, self.Setup.Format,
			gl.UNSIGNED_BYTE,
			nil)
	} else {
		gl.TexImage2D(gl.TEXTURE_2D, 0, self.Setup.InternalFormat,
			self.Width, self.Height, 0, self.Setup.Format,
			gl.UNSIGNED_BYTE,
			data)
	}

	gl.BindTexture(gl.TEXTURE_2D, 0)
}
Example #4
0
func (self *Texture) Unbind(i int) {
	gl.ActiveTexture(gl.GLenum(gl.TEXTURE0 + i))
	gl.BindTexture(gl.TEXTURE_2D, 0)
}