diff --git a/punyverse/entity.py b/punyverse/entity.py index b06afc1..a5c171a 100644 --- a/punyverse/entity.py +++ b/punyverse/entity.py @@ -247,16 +247,26 @@ class Body(Entity): return self.orbit_vbo def _draw_orbits(self, distance): - with glRestore(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT): - glLoadMatrixf(self.parent.orbit_matrix) + shader = self.world.activate_shader('line') + solid = distance < self.parent.orbit_opaque + alpha = 1 if solid else (1 - (distance - self.parent.orbit_opaque) / self.parent.orbit_blend) + shader.uniform_vec4('u_color', 1, 1, 1, alpha) + shader.uniform_mat4('u_mvpMatrix', self.world.projection_matrix() * self.parent.orbit_matrix) - glDisable(GL_LIGHTING) - solid = distance < self.parent.orbit_opaque - glColor4f(1, 1, 1, 1 if solid else (1 - (distance - self.parent.orbit_opaque) / self.parent.orbit_blend)) - if not solid: - glEnable(GL_BLEND) - glLineWidth(1) - self.get_orbit().draw() + if not solid: + glEnable(GL_BLEND) + + orbit = self.get_orbit() + glBindBuffer(GL_ARRAY_BUFFER, orbit.vbo) + shader.vertex_attribute('a_position', orbit.position_size, orbit.type, GL_FALSE, + orbit.stride, orbit.position_offset) + glDrawArrays(GL_LINE_LOOP, 0, orbit.vertex_count) + shader.deactivate_attributes() + glBindBuffer(GL_ARRAY_BUFFER, 0) + + if not solid: + glDisable(GL_BLEND) + self.world.activate_shader(None) def draw(self, options): self._draw(options) diff --git a/punyverse/glgeom.py b/punyverse/glgeom.py index 2193f15..ad23a33 100644 --- a/punyverse/glgeom.py +++ b/punyverse/glgeom.py @@ -251,6 +251,12 @@ class Cube(object): class OrbitVBO(object): + type = GL_FLOAT + stride = 3 * 4 + position_offset = 0 + position_size = 3 + vertex_count = 360 + def __init__(self, orbit): buffer = 360 * 3 * [0] for theta in range(360): @@ -259,14 +265,6 @@ class OrbitVBO(object): self.vbo = array_to_gl_buffer(buffer) - def draw(self): - with glRestoreClient(GL_CLIENT_VERTEX_ARRAY_BIT): - glBindBuffer(GL_ARRAY_BUFFER, self.vbo) - glEnableClientState(GL_VERTEX_ARRAY) - glVertexPointer(3, GL_FLOAT, 12, 0) - glDrawArrays(GL_LINE_LOOP, 0, 360) - glBindBuffer(GL_ARRAY_BUFFER, 0) - def close(self): if self.vbo is not None: vbo = c_uint(self.vbo) diff --git a/punyverse/shaders/line.vertex.glsl b/punyverse/shaders/line.vertex.glsl index 2a01d02..cc7defd 100644 --- a/punyverse/shaders/line.vertex.glsl +++ b/punyverse/shaders/line.vertex.glsl @@ -1,8 +1,8 @@ #version 130 -in vec2 a_position; +in vec3 a_position; uniform mat4 u_mvpMatrix; void main() { - gl_Position = u_mvpMatrix * vec4(a_position, 0, 1); + gl_Position = u_mvpMatrix * vec4(a_position, 1); }