Beispiel #1
0
// Entry point of program
func main() {
	// Creates the Window Wrapper
	glw := wrapper.NewWrapper(windowWidth, windowHeight, "Lab 3: Lights")
	glw.SetFPS(windowFPS)

	// Creates the Window
	glw.CreateWindow()

	// Sets the Event Callbacks
	glw.SetRenderCallback(drawLoop)
	glw.SetKeyCallBack(keyCallback)
	glw.SetReshapeCallback(reshape)

	// Initializes the App
	InitApp(glw)

	// Starts the Rendering Loop
	glw.StartLoop()

	// Sets the Viewport (Important !!, this has to run after the loop!!)
	defer gl.Viewport(0, 0, windowWidth, windowHeight)
}
Beispiel #2
0
//
// Reshape
// This gets called when the window changes its size
//
// @param window (*glfw.Window) a pointer to the window
// @param width (int) the width of the window
// @param height (int) the height of the window
//
func reshape(window *glfw.Window, width, height int) {
	gl.Viewport(0, 0, int32(width), int32(height))
	aspect_ratio = (float32(width) / 640.0 * 4.0) / (float32(height) / 480.0 * 3.0)
}
Beispiel #3
0
func render(w *glfw.Window, r *gResources) {

	width, height := w.GetFramebufferSize()
	ratio := float32(width) / float32(height)

	var xmul, ymul float32
	if ratio > 1 {
		xmul, ymul = ra/ratio, ra
	} else {
		xmul, ymul = ra, ra*ratio
	}

	d := time.Since(start).Seconds()
	sin := float32(math.Sin(d))
	cos := float32(math.Cos(d))

	gl.Viewport(0, 0, int32(width), int32(height))
	gl.Clear(gl.COLOR_BUFFER_BIT)

	////////////////

	// axes

	gl.UseProgram(r.program1)

	gl.BindBuffer(gl.ARRAY_BUFFER, r.vertexBuffer1)

	gl.VertexAttribPointer(
		uint32(r.attributes1.position), // attribute
		2,               // size
		gl.FLOAT,        // type
		false,           // normalized?
		8,               // stride
		gl.PtrOffset(0)) // array buffer offset
	gl.EnableVertexAttribArray(uint32(r.attributes1.position))

	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, r.elementBuffer1)

	gl.LineWidth(1)
	gl.DrawElements(
		gl.LINES,        // mode
		4,               // count
		gl.UNSIGNED_INT, // type
		gl.PtrOffset(0)) // element array buffer offset

	gl.DisableVertexAttribArray(uint32(r.attributes1.position))

	////////////////

	// triangle

	gl.UseProgram(r.program2)

	gl.Uniform1f(r.uniforms2.xmul, xmul)
	gl.Uniform1f(r.uniforms2.ymul, ymul)
	gl.Uniform1f(r.uniforms2.sin, sin)
	gl.Uniform1f(r.uniforms2.cos, cos)

	gl.BindBuffer(gl.ARRAY_BUFFER, r.vertexBuffer2)

	gl.VertexAttribPointer(
		uint32(r.attributes2.position), // attribute
		2,               // size
		gl.FLOAT,        // type
		false,           // normalized?
		8,               // stride
		gl.PtrOffset(0)) // array buffer offset
	gl.EnableVertexAttribArray(uint32(r.attributes2.position))

	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, r.elementBuffer2)

	gl.EnableVertexAttribArray(uint32(r.attributes2.color))
	gl.BindBuffer(gl.ARRAY_BUFFER, r.colorBuffer2)
	gl.VertexAttribPointer(
		uint32(r.attributes2.color), // attribute
		3,               // size
		gl.FLOAT,        // type
		false,           // normalized?
		0,               // stride
		gl.PtrOffset(0)) // array buffer offset

	gl.DrawElements(
		gl.TRIANGLES,    // mode
		3,               // count
		gl.UNSIGNED_INT, // type
		gl.PtrOffset(0)) // element array buffer offset

	////////////////

	// circle

	gl.BindBuffer(gl.ARRAY_BUFFER, r.vertexBuffer3)

	gl.VertexAttribPointer(
		uint32(r.attributes2.position), // attribute
		2,               // size
		gl.FLOAT,        // type
		false,           // normalized?
		8,               // stride
		gl.PtrOffset(0)) // array buffer offset

	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, r.elementBuffer3)

	gl.BindBuffer(gl.ARRAY_BUFFER, r.colorBuffer3)

	gl.VertexAttribPointer(
		uint32(r.attributes2.color), // attribute
		3,               // size
		gl.FLOAT,        // type
		false,           // normalized?
		0,               // stride
		gl.PtrOffset(0)) // array buffer offset

	gl.LineWidth(5)
	gl.DrawElements(
		gl.LINE_LOOP,    // mode
		r.len3,          // count
		gl.UNSIGNED_INT, // type
		gl.PtrOffset(0)) // element array buffer offset

	gl.DisableVertexAttribArray(uint32(r.attributes2.color))
	gl.DisableVertexAttribArray(uint32(r.attributes2.position))

}