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
674289a8b3
commit
e91bc2c21c
|
@ -247,16 +247,26 @@ class Body(Entity):
|
||||||
return self.orbit_vbo
|
return self.orbit_vbo
|
||||||
|
|
||||||
def _draw_orbits(self, distance):
|
def _draw_orbits(self, distance):
|
||||||
with glRestore(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT):
|
shader = self.world.activate_shader('line')
|
||||||
glLoadMatrixf(self.parent.orbit_matrix)
|
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)
|
if not solid:
|
||||||
solid = distance < self.parent.orbit_opaque
|
glEnable(GL_BLEND)
|
||||||
glColor4f(1, 1, 1, 1 if solid else (1 - (distance - self.parent.orbit_opaque) / self.parent.orbit_blend))
|
|
||||||
if not solid:
|
orbit = self.get_orbit()
|
||||||
glEnable(GL_BLEND)
|
glBindBuffer(GL_ARRAY_BUFFER, orbit.vbo)
|
||||||
glLineWidth(1)
|
shader.vertex_attribute('a_position', orbit.position_size, orbit.type, GL_FALSE,
|
||||||
self.get_orbit().draw()
|
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):
|
def draw(self, options):
|
||||||
self._draw(options)
|
self._draw(options)
|
||||||
|
|
|
@ -251,6 +251,12 @@ class Cube(object):
|
||||||
|
|
||||||
|
|
||||||
class OrbitVBO(object):
|
class OrbitVBO(object):
|
||||||
|
type = GL_FLOAT
|
||||||
|
stride = 3 * 4
|
||||||
|
position_offset = 0
|
||||||
|
position_size = 3
|
||||||
|
vertex_count = 360
|
||||||
|
|
||||||
def __init__(self, orbit):
|
def __init__(self, orbit):
|
||||||
buffer = 360 * 3 * [0]
|
buffer = 360 * 3 * [0]
|
||||||
for theta in range(360):
|
for theta in range(360):
|
||||||
|
@ -259,14 +265,6 @@ class OrbitVBO(object):
|
||||||
|
|
||||||
self.vbo = array_to_gl_buffer(buffer)
|
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):
|
def close(self):
|
||||||
if self.vbo is not None:
|
if self.vbo is not None:
|
||||||
vbo = c_uint(self.vbo)
|
vbo = c_uint(self.vbo)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#version 130
|
#version 130
|
||||||
|
|
||||||
in vec2 a_position;
|
in vec3 a_position;
|
||||||
uniform mat4 u_mvpMatrix;
|
uniform mat4 u_mvpMatrix;
|
||||||
|
|
||||||
void main() {
|
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