• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gl.GetUniformLocation函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/mobile/gl.GetUniformLocation函数的典型用法代码示例。如果您正苦于以下问题:Golang GetUniformLocation函数的具体用法?Golang GetUniformLocation怎么用?Golang GetUniformLocation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetUniformLocation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Start

func (e *Engine) Start() {
	var err error

	e.shader.program, err = LoadProgram("shader.v.glsl", "shader.f.glsl")
	if err != nil {
		panic(fmt.Sprintln("LoadProgram failed:", err))
	}

	e.shape.buf = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)
	gl.BufferData(gl.ARRAY_BUFFER, EncodeObject(cubeData), gl.STATIC_DRAW)

	e.shader.vertCoord = gl.GetAttribLocation(e.shader.program, "vertCoord")
	e.shader.vertTexCoord = gl.GetAttribLocation(e.shader.program, "vertTexCoord")

	e.shader.projection = gl.GetUniformLocation(e.shader.program, "projection")
	e.shader.view = gl.GetUniformLocation(e.shader.program, "view")
	e.shader.model = gl.GetUniformLocation(e.shader.program, "model")

	e.shape.texture, err = LoadTexture("gopher.png")
	if err != nil {
		panic(fmt.Sprintln("LoadTexture failed:", err))
	}

	e.started = time.Now()
}
开发者ID:lovexiaov,项目名称:gomobileapp,代码行数:26,代码来源:main.go


示例2: onStart

func onStart() {
	var err error
	program, err = glutil.CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	//创建一个WebGLBuffer对象,把它绑定到顶点缓冲上,并把顶点数据载入到顶点冲。
	buf = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.BufferData(gl.ARRAY_BUFFER, lineData, gl.STATIC_DRAW)

	/*opengl中三种变量
	  uniform变量是外部application程序传递给(vertex和fragment)shader的变量。因此它是application通过函数glUniform**()函数赋值的。
	  在(vertex和fragment)shader程序内部,uniform变量就像是C语言里面的常量(const ),它不能被shader程序修改。(shader只能用,不能改)

	  attribute变量是只能在vertex shader中使用的变量。(它不能在fragment shader中声明attribute变量,也不能被fragment shader中使用)
	  一般用attribute变量来表示一些顶点的数据,如:顶点坐标,法线,纹理坐标,顶点颜色等。
	  在application中,一般用函数glBindAttribLocation()来绑定每个attribute变量的位置,然后用函数glVertexAttribPointer()为每个attribute变量赋值。

	  varying变量是vertex和fragment shader之间做数据传递用的。一般vertex shader修改varying变量的值,然后fragment shader使用该varying变量的值。
	  因此varying变量在vertex和fragment shader二者之间的声明必须是一致的。application不能使用此变量。
	*/
	position = gl.GetAttribLocation(program, "position") //获取位置对象(索引)
	color = gl.GetUniformLocation(program, "color")      // 获取颜色对象(索引)
	scan = gl.GetUniformLocation(program, "scan")        // 获取偏移对象(索引)
	// fmt.Println(position.String(),color.String(),offset.String())//Attrib(0) Uniform(1) Uniform(0)
	// TODO(crawshaw): the debug package needs to put GL state init here
	// Can this be an event.Register call now??
}
开发者ID:lovexiaov,项目名称:gomobileapp,代码行数:31,代码来源:main.go


示例3: start

func start() {
	var err error
	glimage.program, err = CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		panic(err)
	}

	glimage.quadXY = gl.CreateBuffer()
	glimage.quadUV = gl.CreateBuffer()

	gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadXY)
	gl.BufferData(gl.ARRAY_BUFFER, quadXYCoords, gl.STATIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV)
	gl.BufferData(gl.ARRAY_BUFFER, quadUVCoords, gl.STATIC_DRAW)

	glimage.pos = gl.GetAttribLocation(glimage.program, "pos")
	glimage.mvp = gl.GetUniformLocation(glimage.program, "mvp")
	glimage.uvp = gl.GetUniformLocation(glimage.program, "uvp")
	glimage.inUV = gl.GetAttribLocation(glimage.program, "inUV")
	glimage.textureSample = gl.GetUniformLocation(glimage.program, "textureSample")

	texmap.Lock()
	defer texmap.Unlock()
	for key, tex := range texmap.texs {
		texmap.init(key)
		tex.needsUpload = true
	}
}
开发者ID:rockxcn,项目名称:mobile,代码行数:28,代码来源:glimage.go


示例4: onStart

func onStart() {
	var err error
	program, err = glutil.CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	buf = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.BufferData(gl.ARRAY_BUFFER, rectData, gl.STATIC_DRAW)

	position = gl.GetAttribLocation(program, "position")
	color = gl.GetUniformLocation(program, "color")
	offset = gl.GetUniformLocation(program, "offset")
}
开发者ID:natasharomanoff,项目名称:blinker,代码行数:16,代码来源:main.go


示例5: initGL

func initGL() {
	var err error
	program, err = glutil.CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	buf = gl.GenBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, triangleData)

	position = gl.GetAttribLocation(program, "position")
	color = gl.GetUniformLocation(program, "color")
	offset = gl.GetUniformLocation(program, "offset")
	touchLoc = geom.Point{geom.Width / 2, geom.Height / 2}
}
开发者ID:xfong,项目名称:gocl,代码行数:17,代码来源:main.go


示例6: Uniform

func (shader *shader) Uniform(name string) gl.Uniform {
	v, ok := shader.uniforms[name]
	if !ok {
		v = gl.GetUniformLocation(shader.program, name)
		shader.uniforms[name] = v
	}
	return v
}
开发者ID:shazow,项目名称:linerage3d,代码行数:8,代码来源:shader.go


示例7: onStart

func onStart() {
	var err error
	program, err = glutil.CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	buf = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)

	position = gl.GetAttribLocation(program, "position")
	color = gl.GetUniformLocation(program, "color")
	offset = gl.GetUniformLocation(program, "offset")

	// TODO(crawshaw): the debug package needs to put GL state init here
	// Can this be an app.RegisterFilter call now??
}
开发者ID:paulhankin,项目名称:mobile,代码行数:19,代码来源:main.go


示例8: onPaint

func onPaint(sz size.Event) {
	gl.ClearColor(rgb(156), rgb(39), rgb(176), 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	var rotationMatrix = []float32{
		f32.Cos(-alpha), -f32.Sin(-alpha), 0.0,
		f32.Sin(-alpha), f32.Cos(-alpha), 0.0,
		0.0, 0.0, 1.0,
	}

	gl.UseProgram(program)
	// setting color
	gl.Uniform4f(color, rgb(255), rgb(255), rgb(255), 1)
	gl.UniformMatrix3fv(matrixId, rotationMatrix)
	gl.Uniform1f(resolutionId, resIndex)

	gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer)

	gl.EnableVertexAttribArray(position)
	gl.VertexAttribPointer(position, 3, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.LINES, 0, 16)
	gl.DisableVertexAttribArray(position)

	gl.UseProgram(texProgram)
	// setting color
	gl.Uniform4f(color2, rgb(130), rgb(50), rgb(80), 1)
	gl.Uniform1f(resolutionId2, resIndex)
	gl.UniformMatrix3fv(matrixId2, rotationMatrix)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer)
	gl.EnableVertexAttribArray(position2)
	gl.VertexAttribPointer(position2, 3, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer)
	gl.EnableVertexAttribArray(textureCoords)
	gl.VertexAttribPointer(textureCoords, 2, gl.FLOAT, false, 0, 0)

	gl.Uniform1i(gl.GetUniformLocation(texProgram, "myTexture"), 0)
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, textureId)

	gl.DrawArrays(gl.TRIANGLES, 0, 6)
	gl.DisableVertexAttribArray(position2)
	gl.DisableVertexAttribArray(textureCoords)

	if spin == true {
		alpha += 0.1
	}

	if alpha >= 360 {
		alpha = 0.0
	}

}
开发者ID:gitter-badger,项目名称:bukkake,代码行数:54,代码来源:main.go


示例9: glInit

func glInit() {
	var err error
	glimage.program, err = CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		panic(err)
	}

	glimage.quadXY = gl.GenBuffer()
	glimage.quadUV = gl.GenBuffer()

	gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadXY)
	gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, quadXYCoords)
	gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV)
	gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, quadUVCoords)

	glimage.pos = gl.GetAttribLocation(glimage.program, "pos")
	glimage.mvp = gl.GetUniformLocation(glimage.program, "mvp")
	glimage.uvp = gl.GetUniformLocation(glimage.program, "uvp")
	glimage.inUV = gl.GetAttribLocation(glimage.program, "inUV")
	glimage.textureSample = gl.GetUniformLocation(glimage.program, "textureSample")
}
开发者ID:Miaque,项目名称:mojo,代码行数:21,代码来源:glimage.go


示例10: initKeys

func initKeys() {
	var err error
	program, err = glutil.CreateProgram(
		`#version 100
		uniform mat4 projection;
		attribute vec3 position;
		attribute float pointsize;
		void main() {
			gl_Position = projection * vec4(position, 1);
			gl_PointSize = pointsize;
		}`,
		`#version 100
		precision mediump float;
		uniform vec4 color;
		void main(void)
		{
		    vec2 v = 2.0*gl_PointCoord.xy - vec2(1.0);
			float r2 = dot(v, v);
			gl_FragColor = mix(color, vec4(0), r2);
		}`,
	)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	gl.Enable(34370) // GL_PROGRAM_POINT_SIZE; apparently not necessary on Android
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR)

	projection = gl.GetUniformLocation(program, "projection")
	updateProjectionMatrix()

	position = gl.GetAttribLocation(program, "position")
	pointsize = gl.GetAttribLocation(program, "pointsize")
	color = gl.GetUniformLocation(program, "color")
	positionbuf = gl.CreateBuffer()
	pointsizebuf = gl.CreateBuffer()
	updateKeys(ratio{1, 1})
}
开发者ID:gordonklaus,项目名称:justkeys,代码行数:40,代码来源:key.go


示例11: NewTexture

func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) {
	s.mu.Lock()
	defer s.mu.Unlock()

	if !gl.IsProgram(s.texture.program) {
		p, err := compileProgram(textureVertexSrc, textureFragmentSrc)
		if err != nil {
			return nil, err
		}
		s.texture.program = p
		s.texture.pos = gl.GetAttribLocation(p, "pos")
		s.texture.mvp = gl.GetUniformLocation(p, "mvp")
		s.texture.uvp = gl.GetUniformLocation(p, "uvp")
		s.texture.inUV = gl.GetAttribLocation(p, "inUV")
		s.texture.sample = gl.GetUniformLocation(p, "sample")
		s.texture.quadXY = gl.CreateBuffer()
		s.texture.quadUV = gl.CreateBuffer()

		gl.BindBuffer(gl.ARRAY_BUFFER, s.texture.quadXY)
		gl.BufferData(gl.ARRAY_BUFFER, quadXYCoords, gl.STATIC_DRAW)
		gl.BindBuffer(gl.ARRAY_BUFFER, s.texture.quadUV)
		gl.BufferData(gl.ARRAY_BUFFER, quadUVCoords, gl.STATIC_DRAW)
	}

	t := &textureImpl{
		id:   gl.CreateTexture(),
		size: size,
	}

	gl.BindTexture(gl.TEXTURE_2D, t.id)
	gl.TexImage2D(gl.TEXTURE_2D, 0, size.X, size.Y, gl.RGBA, gl.UNSIGNED_BYTE, nil)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	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)

	return t, nil
}
开发者ID:kleopatra999,项目名称:exp,代码行数:38,代码来源:screen.go


示例12: Fill

func (w *windowImpl) Fill(dr image.Rectangle, src color.Color, op draw.Op) {
	if !gl.IsProgram(w.s.fill.program) {
		p, err := compileProgram(fillVertexSrc, fillFragmentSrc)
		if err != nil {
			// TODO: initialize this somewhere else we can better handle the error.
			panic(err.Error())
		}
		w.s.fill.program = p
		w.s.fill.pos = gl.GetAttribLocation(p, "pos")
		w.s.fill.mvp = gl.GetUniformLocation(p, "mvp")
		w.s.fill.color = gl.GetUniformLocation(p, "color")
		w.s.fill.quadXY = gl.CreateBuffer()

		gl.BindBuffer(gl.ARRAY_BUFFER, w.s.fill.quadXY)
		gl.BufferData(gl.ARRAY_BUFFER, quadXYCoords, gl.STATIC_DRAW)
	}

	gl.UseProgram(w.s.fill.program)
	writeAff3(w.s.fill.mvp, w.vertexAff3(dr))

	r, g, b, a := src.RGBA()
	gl.Uniform4f(
		w.s.fill.color,
		float32(r)/65535,
		float32(g)/65535,
		float32(b)/65535,
		float32(a)/65535,
	)

	gl.BindBuffer(gl.ARRAY_BUFFER, w.s.fill.quadXY)
	gl.EnableVertexAttribArray(w.s.fill.pos)
	gl.VertexAttribPointer(w.s.fill.pos, 2, gl.FLOAT, false, 0, 0)

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)

	gl.DisableVertexAttribArray(w.s.fill.pos)
}
开发者ID:kleopatra999,项目名称:exp,代码行数:37,代码来源:window.go


示例13: Start

func (e *Engine) Start() {
	var err error

	e.shader.program, err = LoadProgram("shader.v.glsl", "shader.f.glsl")
	if err != nil {
		panic(fmt.Sprintln("LoadProgram failed:", err))
	}

	e.shader.models, err = wavefront.Read("girl.obj")
	check(err)

	e.shader.vertCoord = gl.GetAttribLocation(e.shader.program, "vertCoord")
	e.shader.vertTexCoord = gl.GetAttribLocation(e.shader.program, "vertTexCoord")
	e.shader.projection = gl.GetUniformLocation(e.shader.program, "projection")
	e.shader.view = gl.GetUniformLocation(e.shader.program, "view")
	e.shader.modelx = gl.GetUniformLocation(e.shader.program, "modelx")
	e.shader.modely = gl.GetUniformLocation(e.shader.program, "modely")
	e.shader.color = gl.GetUniformLocation(e.shader.program, "color")
	e.shader.useuv = gl.GetUniformLocation(e.shader.program, "useuv")

	for _, model := range e.shader.models {
		for _, group := range model.Groups {
			//颜色
			color := group.Material.Ambient
			//顶点
			data := f32.Bytes(binary.LittleEndian, group.Vertexes...)
			vertexCount := len(group.Vertexes) / 3
			databuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, databuf)
			gl.BufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW)
			//UV坐标
			textcoords := f32.Bytes(binary.LittleEndian, group.Textcoords...)
			uvbuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, uvbuf)
			gl.BufferData(gl.ARRAY_BUFFER, textcoords, gl.STATIC_DRAW)
			//贴图文件
			var useuv bool
			tex, err := LoadTexture(group.Material.Texturefile)
			if err != nil {
				useuv = false
			} else {
				useuv = true
			}
			e.shape.Objs = append(e.shape.Objs, Obj{vcount: vertexCount, coord: databuf, color: color, useuv: useuv, uvcoord: uvbuf, tex: tex})

		}

	}
}
开发者ID:lomoalbert,项目名称:gomobileapp,代码行数:49,代码来源:main.go


示例14: onStart

func onStart() {
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)

	texture := loadImages("495.png")

	textureId = gl.CreateTexture()
	gl.BindTexture(gl.TEXTURE_2D, textureId)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	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, texture.Rect.Size().X, texture.Rect.Size().Y, gl.RGBA, gl.UNSIGNED_BYTE, texture.Pix)

	// loading Shaders & linking programs
	program = createProgram("vShader.vs", "fShader.vs")
	texProgram = createProgram("vTexShader.vs", "fTexShader.vs")

	quadBuffer = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, quadData, gl.STATIC_DRAW)

	quadTexBuffer = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, quadTexData, gl.STATIC_DRAW)

	swasBuffer = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, swastikaData, gl.STATIC_DRAW)

	position = gl.GetAttribLocation(program, "position")
	color = gl.GetUniformLocation(program, "color")
	matrixId = gl.GetUniformLocation(program, "rotationMatrix")
	resolutionId = gl.GetUniformLocation(program, "resIndex")

	position2 = gl.GetAttribLocation(texProgram, "position")
	textureCoords = gl.GetAttribLocation(texProgram, "texCoords")
	matrixId2 = gl.GetUniformLocation(texProgram, "rotationMatrix")
	resolutionId2 = gl.GetUniformLocation(texProgram, "resIndex")
	color2 = gl.GetUniformLocation(texProgram, "color")
}
开发者ID:gitter-badger,项目名称:bukkake,代码行数:43,代码来源:main.go


示例15: uniformLocation

func uniformLocation(prog gl.Program, name string) gl.Uniform {
	attrib := gl.GetUniformLocation(prog, name)

	return attrib
}
开发者ID:BluePadge,项目名称:Fergulator-Android,代码行数:5,代码来源:video.go



注:本文中的golang.org/x/mobile/gl.GetUniformLocation函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gl.UseProgram函数代码示例发布时间:2022-05-28
下一篇:
Golang gl.GetAttribLocation函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap