Пример #1
0
//
// Draw Loop Function
// This function gets called on every update.
//
func drawLoop(glw *wrapper.Glw) {
	// Sets the Clear Color (Background Color)
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)

	// Clears the Window
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Enables Depth
	gl.Enable(gl.DEPTH_TEST)

	// Sets the Shader program to Use
	gl.UseProgram(shaderProgram)

	// Define the model transformations for the cube
	cube.ResetModel()
	cube.Translate(x+0.5, y, z)
	cube.Scale(scale, scale, scale)            //scale equally in all axis
	cube.Rotate(-angle_x, mgl32.Vec3{1, 0, 0}) //rotating in clockwise direction around x-axis
	cube.Rotate(-angle_y, mgl32.Vec3{0, 1, 0}) //rotating in clockwise direction around y-axis
	cube.Rotate(-angle_z, mgl32.Vec3{0, 0, 1}) //rotating in clockwise direction around z-axis

	// Define the model transformations for our sphere
	sphere.ResetModel()
	sphere.Translate(-x-0.5, 0, 0)
	sphere.Scale(scale/3.0, scale/3.0, scale/3.0) //scale equally in all axis
	sphere.Rotate(-angle_x, mgl32.Vec3{1, 0, 0})  //rotating in clockwise direction around x-axis
	sphere.Rotate(-angle_y, mgl32.Vec3{0, 1, 0})  //rotating in clockwise direction around y-axis
	sphere.Rotate(-angle_z, mgl32.Vec3{0, 0, 1})  //rotating in clockwise direction around z-axis

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
	var Projection mgl32.Mat4 = mgl32.Perspective(30.0, aspect_ratio, 0.1, 100.0)

	// Camera matrix
	var View mgl32.Mat4 = mgl32.LookAtV(
		mgl32.Vec3{0, 0, 4}, // Camera is at (0,0,4), in World Space
		mgl32.Vec3{0, 0, 0}, // and looks at the origin
		mgl32.Vec3{0, 1, 0}, // Head is up (set to 0,-1,0 to look upside-down)
	)

	// Send our uniforms variables to the currently bound shader,
	gl.Uniform1ui(colourmodeUniform, uint32(colourmode))
	gl.UniformMatrix4fv(viewUniform, 1, false, &View[0])
	gl.UniformMatrix4fv(projectionUniform, 1, false, &Projection[0])

	// Draws the Cube
	gl.UniformMatrix4fv(modelUniform, 1, false, &cube.Model[0])
	cube.Draw()

	// Draw our sphere
	gl.UniformMatrix4fv(modelUniform, 1, false, &sphere.Model[0])
	sphere.DrawSphere()

	gl.DisableVertexAttribArray(0)
	gl.UseProgram(0)

	/* Modify our animation variables */
	angle_x += angle_inc_x
	angle_y += angle_inc_y
	angle_z += angle_inc_z
}
Пример #2
0
func (shaderManager *ShaderManager) SetUniform1ui(shaderName, uniformName string, value uint32) {
	gl.Uniform1ui(shaderManager.GetUniform(shaderName, uniformName), value)
}