mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Convert orbits to shaders.
This commit is contained in:
parent
f5a2839fcf
commit
510dcb46a6
|
@ -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)
|
||||
|
||||
glDisable(GL_LIGHTING)
|
||||
shader = self.world.activate_shader('line')
|
||||
solid = distance < self.parent.orbit_opaque
|
||||
glColor4f(1, 1, 1, 1 if solid else (1 - (distance - self.parent.orbit_opaque) / self.parent.orbit_blend))
|
||||
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)
|
||||
|
||||
if not solid:
|
||||
glEnable(GL_BLEND)
|
||||
glLineWidth(1)
|
||||
self.get_orbit().draw()
|
||||
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue