Пример #1
0
// drawScene renders the 3D models consisting of one VAO
func (tag *trtag) drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	tag.checkError("gl.Clear")
	gl.UseProgram(tag.shaders)
	tag.checkError("gl.UseProgram")
	gl.BindVertexArray(tag.vao)
	tag.checkError("gl.BindVertexArray")

	// Use a modelview matrix and quaternion to rotate the 3D object.
	tag.mvp64.SetQ(lin.NewQ().SetAa(0, 1, 0, lin.Rad(-tag.rotateAngle)))
	tag.mvp64.TranslateMT(0, 0, -4)
	tag.mvp.Set(tag.mvp64.Mult(tag.mvp64, tag.persp))
	gl.UniformMatrix4fv(tag.mvpRef, 1, false, tag.mvp.Pointer())
	if err := gl.GetError(); err != 0 {
		fmt.Printf("gl.UniformMatrix error %d\n", err)
	}
	gl.DrawElements(gl.TRIANGLES, int32(len(tag.faces)), gl.UNSIGNED_BYTE, 0)
	if err := gl.GetError(); err != 0 {
		fmt.Printf("gl.DrawElements error %d\n", err)
	}

	// cleanup
	gl.UseProgram(0)
	tag.checkError("gl.UseProgram-0")
	gl.BindVertexArray(0)
	tag.checkError("gl.BindVertexArray-0")

	// rotate based on time... not on how fast the computer runs.
	if time.Now().Sub(tag.lastTime).Seconds() > 0.01 {
		tag.rotateAngle += 1
		tag.lastTime = time.Now()
	}
}
Пример #2
0
// bindUniform links data to uniforms expected by shaders.
// It expects the variable parameter list types to match the uniform type.
func (gc *opengl) bindUniform(uniform int32, utype, cnt int, udata ...interface{}) {
	switch utype {
	case i1:
		i1 := udata[0].(int32)
		gl.Uniform1i(uniform, i1)
	case f1:
		f1 := udata[0].(float32)
		gl.Uniform1f(uniform, f1)
	case f2:
		f1 := udata[0].(float32)
		f2 := udata[1].(float32)
		gl.Uniform2f(uniform, f1, f2)
	case f3:
		f1 := udata[0].(float32)
		f2 := udata[1].(float32)
		f3 := udata[2].(float32)
		gl.Uniform3f(uniform, f1, f2, f3)
	case f4:
		f1 := udata[0].(float32)
		f2 := udata[1].(float32)
		f3 := udata[2].(float32)
		f4 := udata[3].(float32)
		gl.Uniform4f(uniform, f1, f2, f3, f4)
	case x3:
		mptr := udata[0].(*float32)
		gl.UniformMatrix3fv(uniform, int32(cnt), false, mptr)
	case x34:
		mptr := udata[0].(*float32)
		gl.UniformMatrix3x4fv(uniform, int32(cnt), false, mptr)
	case x4:
		mptr := udata[0].(*float32)
		gl.UniformMatrix4fv(uniform, int32(cnt), false, mptr)
	}
}
Пример #3
0
// drawScene renders the shader-only scene.
func (sf *sftag) drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(sf.shaders)
	gl.BindVertexArray(sf.vao)
	timeSinceStart := time.Since(sf.sTime).Seconds()
	gl.Uniform1f(sf.gTime, float32(timeSinceStart))
	gl.Uniform2f(sf.sizes, 500, 500)
	gl.UniformMatrix4fv(sf.mvpref, 1, false, sf.mvp.Pointer())
	gl.DrawElements(gl.TRIANGLES, int32(len(sf.faces)), gl.UNSIGNED_BYTE, 0)

	// cleanup
	gl.UseProgram(0)
	gl.BindVertexArray(0)
}
Пример #4
0
// drawScene renders the single texture on the quad.
func (rt *rtrace) drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(rt.shaders)
	gl.Uniform1i(rt.tex2D, 0)
	gl.ActiveTexture(gl.TEXTURE0 + 0)
	gl.BindVertexArray(rt.vao)
	gl.UniformMatrix4fv(rt.mvpId, 1, false, rt.mvp.Pointer())
	gl.DrawElements(gl.TRIANGLES, int32(len(rt.faces)), gl.UNSIGNED_BYTE, 0)

	// cleanup
	gl.ActiveTexture(0)
	gl.UseProgram(0)
	gl.BindVertexArray(0)
}
Пример #5
0
Файл: ld.go Проект: toophy/vu
// render draws the scene consisting of one VAO
func (ld *ldtag) render() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(ld.shaders)
	gl.BindVertexArray(ld.vao)

	// use a model-view-projection matrix
	ld.mvp64.Set(lin.M4I).ScaleSM(0.5, 0.5, 0.5).TranslateMT(0, 0, -2)
	ld.mvp.Set(ld.mvp64.Mult(ld.mvp64, ld.persp))
	gl.UniformMatrix4fv(ld.mvpref, 1, false, ld.mvp.Pointer())
	gl.DrawElements(gl.TRIANGLES, ld.faceCount, gl.UNSIGNED_SHORT, 0)

	// cleanup
	gl.UseProgram(0)
	gl.BindVertexArray(0)
}