當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gl21.BindTexture函數代碼示例

本文整理匯總了Golang中github.com/chsc/gogl/gl21.BindTexture函數的典型用法代碼示例。如果您正苦於以下問題:Golang BindTexture函數的具體用法?Golang BindTexture怎麽用?Golang BindTexture使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BindTexture函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Draw

// Draw draws the Sprite object.
func (sprite *Sprite) Draw(frame int) error {

	gl.BindBuffer(gl.ARRAY_BUFFER, sprite.shape.vertexBuffer)
	gl.VertexAttribPointer(gl.Uint(0), 2, gl.FLOAT, gl.FALSE, 0, gl.Offset(nil, 0))
	gl.BindAttribLocation(paunchEffect.program, gl.Uint(0), gl.GLString("position"))
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	if sprite.texcoordBuffer != 0 {
		gl.ActiveTexture(gl.TEXTURE0)

		gl.BindBuffer(gl.ARRAY_BUFFER, sprite.texcoordBuffer)
		gl.VertexAttribPointer(gl.Uint(1), 2, gl.FLOAT, gl.FALSE, 0, gl.Offset(nil, 0))
		gl.BindAttribLocation(paunchEffect.program, gl.Uint(0), gl.GLString("texcoord"))
		gl.BindBuffer(gl.ARRAY_BUFFER, 0)

		gl.BindTexture(gl.TEXTURE_2D, sprite.texture[frame])
		gl.EnableVertexAttribArray(gl.Uint(1))
	}

	gl.EnableVertexAttribArray(gl.Uint(0))
	gl.DrawArrays(gl.TRIANGLES, 0, gl.Sizei(sprite.shape.size))
	gl.DisableVertexAttribArray(gl.Uint(0))
	gl.DisableVertexAttribArray(gl.Uint(1))

	gl.BindTexture(gl.TEXTURE_2D, 0)

	return checkForErrors()
}
開發者ID:velovix,項目名稱:paunch,代碼行數:29,代碼來源:sprite.go

示例2: Render

func (w *glfwBackend) Render(console *Console) {
	if w.Running() {
		w.mouse.Left.Released = false
		w.mouse.Right.Released = false
		w.mouse.Middle.Released = false
		w.key = NOKEY

		gl.Clear(gl.COLOR_BUFFER_BIT)

		gl.BindTexture(gl.TEXTURE_2D, textures[1])
		for y := 0; y < console.Height(); y++ {
			for x := 0; x < console.Width(); x++ {
				_, bg, _ := console.Get(x, y)
				w.letter(x, y, 0, bg)
			}
		}

		gl.BindTexture(gl.TEXTURE_2D, textures[0])
		for y := 0; y < console.Height(); y++ {
			for x := 0; x < console.Width(); x++ {
				fg, _, ch := console.Get(x, y)
				if position, ok := w.font.Map(ch); ok {
					w.letter(x, y, position, fg)
				}
			}
		}

		glfw.SwapBuffers()
	}
}
開發者ID:ajhager,項目名稱:rog,代碼行數:30,代碼來源:backend.go

示例3: Draw

func (ms *ManaSource) Draw(local *LocalData, zoom float64, dx float64, dy float64) {
	if local.nodeTextureData == nil {
		//		gl.Enable(gl.TEXTURE_2D)
		local.nodeTextureData = make([]byte, ms.options.NumNodeRows*ms.options.NumNodeCols*3)
		gl.GenTextures(1, &local.nodeTextureId)
		gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
		gl.TexImage2D(
			gl.TEXTURE_2D,
			0,
			gl.RGB,
			gl.Sizei(ms.options.NumNodeRows),
			gl.Sizei(ms.options.NumNodeCols),
			0,
			gl.RGB,
			gl.UNSIGNED_BYTE,
			gl.Pointer(&local.nodeTextureData[0]))
	}
	for i := range ms.rawNodes {
		for c := 0; c < 3; c++ {
			color_frac := ms.rawNodes[i].Mana[c] * 1.0 / ms.options.NodeMagnitude
			color_range := float64(ms.options.MaxNodeBrightness - ms.options.MinNodeBrightness)
			local.nodeTextureData[i*3+c] = byte(
				color_frac*color_range + float64(ms.options.MinNodeBrightness))
		}
	}
	gl.Enable(gl.TEXTURE_2D)
	//gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
	gl.TexSubImage2D(
		gl.TEXTURE_2D,
		0,
		0,
		0,
		gl.Sizei(ms.options.NumNodeRows),
		gl.Sizei(ms.options.NumNodeCols),
		gl.RGB,
		gl.UNSIGNED_BYTE,
		gl.Pointer(&local.nodeTextureData[0]))

	base.EnableShader("nodes")
	base.SetUniformI("nodes", "width", ms.options.NumNodeRows*3)
	base.SetUniformI("nodes", "height", ms.options.NumNodeCols*3)
	base.SetUniformI("nodes", "drains", 1)
	base.SetUniformI("nodes", "tex0", 0)
	base.SetUniformI("nodes", "tex1", 1)
	base.SetUniformF("nodes", "zoom", float32(zoom))
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)

	// I have no idea why this value for move works, but it does.  So, hooray.
	move := (dx - dy) / 2
	texture.RenderAdvanced(move, -move, dy, dx, 3.1415926535/2, true)
	base.EnableShader("")
	gl.Disable(gl.TEXTURE_2D)
}
開發者ID:runningwild,項目名稱:magnus,代碼行數:60,代碼來源:mana_source.go

示例4: Bind

func (d *Data) Bind() {
	if d.texture == 0 {
		if error_texture == 0 {
			makeErrorTexture()
		}
		gl.BindTexture(gl.TEXTURE_2D, error_texture)
	} else {
		gl.BindTexture(gl.TEXTURE_2D, d.texture)
	}
}
開發者ID:dgthunder,項目名稱:magnus,代碼行數:10,代碼來源:manager.go

示例5: Bind

func (d *Data) Bind() {
	if d.texture == 0 {
		if error_texture == 0 {
			makeErrorTexture()
		}
		gl.BindTexture(gl.TEXTURE_2D, error_texture)
		base.Log().Printf("Ninindg error etextures")
	} else {
		gl.BindTexture(gl.TEXTURE_2D, d.texture)
	}
}
開發者ID:runningwild,項目名稱:jbot,代碼行數:11,代碼來源:manager.go

示例6: NewSprite

// NewSprite creates a new Sprite object using the given data, which is
// expected to be in RGBA format. If you use PNG image files, you can use the
// NewSpriteFromImage shortcut function instead.
func NewSprite(x, y, width, height float64, data []byte, clip int) (*Sprite, error) {

	verticies := []float64{
		x, y,
		x + width, y,
		x, y + height,

		x + width, y + height,
		x + width, y,
		x, y + height}

	shape, err := NewShape(gl.TRIANGLES, verticies)
	if err != nil {
		return nil, err
	}

	sprite := &Sprite{texcoordBuffer: 0, texture: nil, shape: shape}

	texCoords := []float32{
		0, 0,
		1, 0,
		0, 1,

		1, 1,
		1, 0,
		0, 1}

	gl.GenBuffers(1, &sprite.texcoordBuffer)
	gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(sprite.texcoordBuffer))
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(len(texCoords)*4), gl.Pointer(&texCoords[0]), gl.STREAM_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	sprite.texture = make([]gl.Uint, clip)
	gl.GenTextures(gl.Sizei(clip), &sprite.texture[0])

	clips := make([][]byte, clip)
	for i := range clips {
		clips[i] = data[i*(len(data)/len(clips)) : (i+1)*(len(data)/len(clips))]
		gl.BindTexture(gl.TEXTURE_2D, sprite.texture[len(clips)-1-i])
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
		gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA,
			gl.Sizei(width), gl.Sizei(height),
			0, gl.RGBA, gl.UNSIGNED_BYTE,
			gl.Pointer(&clips[i][0]))
	}

	gl.BindTexture(gl.TEXTURE_2D, 0)

	return sprite, checkForErrors()
}
開發者ID:velovix,項目名稱:paunch,代碼行數:56,代碼來源:sprite.go

示例7: texinit

func texinit(id int) {
	gl.BindTexture(gl.TEXTURE_2D, gl.Uint(id))
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
}
開發者ID:jacereda,項目名稱:webmplay,代碼行數:7,代碼來源:webmplay.go

示例8: createTexture

func createTexture(r io.Reader) (textureId gl.Uint, err error) {
	img, err := png.Decode(r)
	if err != nil {
		return 0, err
	}

	rgbaImg, ok := img.(*image.NRGBA)
	if !ok {
		return 0, errors.New("texture must be an NRGBA image")
	}

	gl.GenTextures(1, &textureId)
	gl.BindTexture(gl.TEXTURE_2D, textureId)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	// flip image: first pixel is lower left corner
	imgWidth, imgHeight := img.Bounds().Dx(), img.Bounds().Dy()
	data := make([]byte, imgWidth*imgHeight*4)
	lineLen := imgWidth * 4
	dest := len(data) - lineLen
	for src := 0; src < len(rgbaImg.Pix); src += rgbaImg.Stride {
		copy(data[dest:dest+lineLen], rgbaImg.Pix[src:src+rgbaImg.Stride])
		dest -= lineLen
	}
	gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.Sizei(imgWidth), gl.Sizei(imgHeight), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))

	return textureId, nil
}
開發者ID:sserafimescu,項目名稱:gogl,代碼行數:29,代碼來源:gopher.go

示例9: upload

func upload(id gl.Uint, data []byte, stride int, w int, h int) {
	gl.BindTexture(gl.TEXTURE_2D, id)
	gl.PixelStorei(gl.UNPACK_ROW_LENGTH, gl.Int(stride))
	gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE,
		gl.Sizei(w), gl.Sizei(h), 0,
		gl.LUMINANCE, gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))
}
開發者ID:jacereda,項目名稱:webmplay,代碼行數:8,代碼來源:webmplay.go

示例10: Draw

func (self *Tile) Draw() {
	switch self.CurrentLOD {
	case -1:
		// TODO: draw single color
		r, i := self.What.Center()
		c := complex(r, i)
		color := mandelbrotAt(c)
		gl.BindTexture(gl.TEXTURE_2D, 0)
		gl.Color3ub(color.R, color.G, color.B)
		drawQuad(self.X, self.Y, self.W, self.H, 0, 0, 1, 1)
		gl.Color3ub(255, 255, 255)
	case 0:
		gl.BindTexture(gl.TEXTURE_2D, self.Texture[0])
		drawQuad(self.X, self.Y, self.W, self.H, 0, 0, 1, 1)
	case 1:
		gl.BindTexture(gl.TEXTURE_2D, self.Texture[1])
		drawQuad(self.X, self.Y, self.W, self.H, 0, 0, 1, 1)
	default:
		panic("unreachable")
	}
}
開發者ID:nsf,項目名稱:gomandel,代碼行數:21,代碼來源:gomandel.go

示例11: makeErrorTexture

func makeErrorTexture() {
	gl.Enable(gl.TEXTURE_2D)
	gl.GenTextures(1, (*gl.Uint)(&error_texture))
	gl.BindTexture(gl.TEXTURE_2D, error_texture)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
	pink := []byte{255, 0, 255, 255}
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.BYTE, gl.Pointer(&pink[0]))
}
開發者ID:runningwild,項目名稱:jbot,代碼行數:12,代碼來源:texture_devel.go

示例12: draw

func (m *Model) draw() {
	m.shader.use()

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, m.texture_id)
	gl.Uniform1i(m.shader.uniform_texture, 0)

	//texcoord
	if m.has_uv {
		gl.BindBuffer(gl.ARRAY_BUFFER, m.texcoord)
		gl.EnableVertexAttribArray(m.shader.attribute_texcoord)
		gl.VertexAttribPointer(
			m.shader.attribute_texcoord,
			2,
			gl.FLOAT,
			gl.FALSE,
			0,
			gl.Pointer(nil))
	}

	gl.BindBuffer(gl.ARRAY_BUFFER, m.buffer)
	gl.EnableVertexAttribArray(m.shader.attribute_vertex)
	gl.VertexAttribPointer(
		m.shader.attribute_vertex,
		3,
		gl.FLOAT,
		gl.FALSE,
		0,
		gl.Pointer(nil))

	gl.BindBuffer(gl.ARRAY_BUFFER, m.normal_buf)
	gl.EnableVertexAttribArray(m.shader.attribute_normal)
	gl.VertexAttribPointer(
		m.shader.attribute_normal,
		3,
		gl.FLOAT,
		gl.FALSE,
		0,
		gl.Pointer(nil))

	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, m.index)
	gl.DrawElements(gl.TRIANGLES, gl.Sizei(len(m.indices)), gl.UNSIGNED_INT, gl.Pointer(nil))

	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, 0)
	gl.DisableVertexAttribArray(m.shader.attribute_vertex)
	gl.DisableVertexAttribArray(m.shader.attribute_normal)
	if m.has_uv {
		gl.DisableVertexAttribArray(m.shader.attribute_texcoord)
	}

}
開發者ID:drasich,項目名稱:ridley,代碼行數:52,代碼來源:model.go

示例13: reuploadTexture

func reuploadTexture(tex *gl.Uint, w, h int, data []byte) {
	if *tex > 0 {
		gl.BindTexture(gl.TEXTURE_2D, *tex)
		gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(w), gl.Sizei(h), 0,
			gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))
		if gl.GetError() != gl.NO_ERROR {
			gl.DeleteTextures(1, tex)
			panic("Failed to reupload texture")
		}
		return
	}
	*tex = uploadTexture_RGBA32(w, h, data)
}
開發者ID:nsf,項目名稱:gomandel,代碼行數:13,代碼來源:gomandel.go

示例14: Bind

func (s *Sprite) Bind() (x, y, x2, y2 float64) {
	var rect FrameRect
	var sh *sheet
	var ok bool
	fid := frameId{facing: s.facing, node: s.anim_node.Id()}
	var dx, dy float64
	if rect, ok = s.shared.connector.rects[fid]; ok {
		sh = s.shared.connector
	} else if rect, ok = s.shared.facings[s.facing].rects[fid]; ok {
		sh = s.shared.facings[s.facing]
	} else {
		gl.BindTexture(gl.TEXTURE_2D, error_texture)
		return
	}
	gl.BindTexture(gl.TEXTURE_2D, sh.texture)
	dx = float64(sh.dx)
	dy = float64(sh.dy)
	x = float64(rect.X) / dx
	y = float64(rect.Y) / dy
	x2 = float64(rect.X2) / dx
	y2 = float64(rect.Y2) / dy
	return
}
開發者ID:runningwild,項目名稱:glop,代碼行數:23,代碼來源:sprite.go

示例15: initTexture

func (m *Model) initTexture() {
	//file, err := os.Open("model/test.png")
	file, err := os.Open("model/ceil.png")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	img, _, err := image.Decode(file)
	if err != nil {
		log.Fatal(err)
	}

	rgbaImg, ok := img.(*image.NRGBA)
	if !ok {
		//return 0, errors.New("texture must be an NRGBA image")
		log.Fatal("image is not rgba")
	}

	gl.GenTextures(1, &m.texture_id)
	gl.BindTexture(gl.TEXTURE_2D, m.texture_id)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	// flip image: first pixel is lower left corner
	img_width, img_height := img.Bounds().Dx(), img.Bounds().Dy()
	data := make([]byte, img_width*img_height*4)
	line_len := img_width * 4
	dest := len(data) - line_len
	for src := 0; src < len(rgbaImg.Pix); src += rgbaImg.Stride {
		copy(data[dest:dest+line_len], rgbaImg.Pix[src:src+rgbaImg.Stride])
		dest -= line_len
	}
	gl.TexImage2D(
		gl.TEXTURE_2D,
		0,
		gl.RGBA, //4,
		gl.Sizei(img_width),
		gl.Sizei(img_height),
		0,
		gl.RGBA,
		gl.UNSIGNED_BYTE,
		gl.Pointer(&data[0]))

}
開發者ID:drasich,項目名稱:ridley,代碼行數:45,代碼來源:model.go


注:本文中的github.com/chsc/gogl/gl21.BindTexture函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。