v/vlib/oldgg/utils.v

38 lines
1.1 KiB
V
Raw Normal View History

2020-06-04 20:18:22 +02:00
module oldgg
2020-01-31 03:43:46 +01:00
import gl
import gx
import math
2020-01-31 03:43:46 +01:00
fn arc_vertices(x, y, r, start_angle, end_angle f32, segments int) []f32 {
mut vertices := []f32{}
2020-01-31 03:43:46 +01:00
start_rads := start_angle * 0.0174533 // deg -> rad approx
end_rads := end_angle * 0.0174533
increment := (end_rads - start_rads) / f32(segments)
2020-02-03 04:01:39 +01:00
vertices << [x + f32(math.cos(start_rads)) * r, y + f32(math.sin(start_rads)) * r] !
2020-01-31 03:43:46 +01:00
mut i := 1
for i < segments {
theta := f32(i) * increment + start_rads
2020-02-03 04:01:39 +01:00
vertices << [x + f32(math.cos(theta)) * r, y + f32(math.sin(theta)) * r] !
2020-01-31 03:43:46 +01:00
i++
}
2020-02-03 04:01:39 +01:00
vertices << [x + f32(math.cos(end_rads)) * r, y + f32(math.sin(end_rads)) * r] !
2020-01-31 03:43:46 +01:00
return vertices
}
fn (ctx &GG) use_color_shader(color gx.Color) {
ctx.shader.set_int('has_texture', 0)
C.glDeleteBuffers(1, &ctx.vao)
C.glDeleteBuffers(1, &ctx.vbo)
ctx.shader.use()
ctx.shader.set_color('color', color)
}
fn (ctx &GG) bind_vertices(vertices []f32) {
gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW)
gl.vertex_attrib_pointer(0, 2, C.GL_FLOAT, false, 2, 0)
gl.enable_vertex_attrib_array(0)
gl.bind_vao(ctx.vao)
}