Пример #1
0
// update handles user input.
func (rt *rtrace) update(dev device.Device) {
	pressed := dev.Update()
	if pressed.Resized {
		_, _, ww, wh := dev.Size()
		gl.Viewport(0, 0, int32(ww), int32(wh))
	}
}
Пример #2
0
Файл: ld.go Проект: toophy/vu
// resize handles user screen/window changes.
func (ld *ldtag) resize(x, y, width, height int) {
	gl.Viewport(0, 0, int32(width), int32(height))
	ld.persp.Persp(60, float64(width)/float64(height), 0.1, 50)
}
Пример #3
0
// resize handles user screen/window changes.
func (sf *sftag) resize(x, y, width, height int) {
	gl.Viewport(0, 0, int32(width), int32(height))
}
Пример #4
0
// Render implementation.
// FUTURE: all kinds of possible optimizations that would need to be
//         profiled before implementing.
//           • group by vao to avoid switching vao's.
//           • group by texture to avoid switching textures.
//           • use interleaved vertex data.
//           • uniform buffers http://www.opengl.org/wiki/Uniform_Buffer_Object.
//           • ... lots more possiblities... leave your fav here.
func (gc *opengl) Render(dr Draw) {
	d, ok := dr.(*draw)
	if !ok || d == nil {
		return
	}

	// switch state only if necessary.
	if gc.depthTest != d.depth {
		if d.depth {
			gl.Enable(gl.DEPTH_TEST)
		} else {
			gl.Disable(gl.DEPTH_TEST)
		}
		gc.depthTest = d.depth
	}

	// switch render framebuffer only if necessary. The framebuffer
	// is used to render to a texture associated with a framebuffer.
	if gc.fbo != d.fbo {
		gl.BindFramebuffer(gl.FRAMEBUFFER, d.fbo)
		if d.fbo == 0 {
			gl.Viewport(0, 0, gc.vw, gc.vh)
		} else {
			gl.Clear(gl.DEPTH_BUFFER_BIT)
			gl.Viewport(0, 0, 1024, 1024) // size convention for framebuffer texture.
		}
		gc.fbo = d.fbo
	}

	// switch shaders only if necessary.
	if gc.shader != d.shader {
		gl.UseProgram(d.shader)
		gc.shader = d.shader
	}

	// Ask the model to bind its provisioned uniforms.
	// FUTURE: only need to bind uniforms that have changed.
	gc.bindUniforms(d)

	// bind the data buffers and render.
	gl.BindVertexArray(d.vao)
	switch d.mode {
	case LINES:
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
		gl.DrawElements(gl.LINES, d.numFaces, gl.UNSIGNED_SHORT, 0)
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
	case POINTS:
		gl.Enable(gl.PROGRAM_POINT_SIZE)
		gl.DrawArrays(gl.POINTS, 0, d.numVerts)
		gl.Disable(gl.PROGRAM_POINT_SIZE)
	case TRIANGLES:
		if len(d.texs) > 1 && d.texs[0].fn > 0 {
			// Multiple textures on one model specify which verticies they apply to.
			for _, tex := range d.texs {
				// Use the same texture unit and sampler. Just update which
				// image is being sampled.
				gl.BindTexture(gl.TEXTURE_2D, tex.tid)
				// fn is the number of triangles, 3 indicies per triangle.
				// f0 is the offset in triangles where each triangle has 3 indicies
				//    of 2 bytes (uShort) each.
				gl.DrawElements(gl.TRIANGLES, tex.fn*3, gl.UNSIGNED_SHORT, int64(3*2*tex.f0))
			}
		} else {
			// Single textures are handled with a standard bindUniforms
			gl.DrawElements(gl.TRIANGLES, d.numFaces, gl.UNSIGNED_SHORT, 0)
		}
	}
}
Пример #5
0
func (gc *opengl) Viewport(width int, height int) {
	gc.vw, gc.vh = int32(width), int32(height)
	gl.Viewport(0, 0, int32(width), int32(height))
}
Пример #6
0
// resize sets the view port size. User resizes are ignored.
func (tag *trtag) resize(width int, height int) {
	gl.Viewport(0, 0, int32(width), int32(height))
	tag.persp.Persp(60, float64(width)/float64(height), 0.1, 50)
}