示例#1
0
        p02 = numpy.array([new_indices_map[p] for p in p02], dtype=dtype)
        p12 = numpy.array([new_indices_map[p] for p in p12], dtype=dtype)
        del new_indices_map

        indices = numpy.vstack([numpy.column_stack(triple) for triple in ((p0, p01, p02), (p01, p1, p12), (p01, p12, p02), (p12, p2, p02))])
        vertices = numpy.vstack((vertices, new_vertices))
        return vertices, indices

    vertices = _vertices
    indices = _indices
    for i in range(level):
        vertices, indices = refine(vertices, indices)
    return vertices, indices


array_spec = glesutils.ArraySpec("vertex_attrib,normal_attrib,texcoord_attrib:3f")

vertex_glsl = array_spec.glsl() + """
uniform mat4 mvp_mat;
uniform mat3 texcoord_mat;

varying vec3 normal_var;
varying vec3 texcoord_var;

void main(void) {
  gl_Position = mvp_mat * vec4(vertex_attrib, 1.0);
  normal_var = normal_attrib;
  texcoord_var = texcoord_mat * texcoord_attrib;
}
"""
示例#2
0
vertices = [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.5, 0.5, 0.0), (0.0, 0.5, 0.0),
            (0.0, 0.0, -0.5), (0.5, 0.0, -0.5), (0.5, 0.5, -0.5),
            (0.0, 0.5, -0.5)]

indices_outer = (0, 1, 2, 3, 0, 4, 5, 1, 5, 6, 2, 6, 7, 3, 7, 4)

vertices_points = []
indices_points = []

for i in range(0, 100):
    vertices_points.append(
        ((20 * random.random()) - 10, (20 * random.random()),
         (20 * random.random()) - 10))
    indices_points.append(i)

array_spec = glesutils.ArraySpec("vertex_attrib:3f")

vertex_glsl = array_spec.glsl() + """
uniform mat4 position_matrix;
uniform mat4 eye_matrix;
uniform mat4 scaling_matrix;
uniform mat4 sound_matrix;
uniform float point_size;

varying float red;

void main(void) {
  gl_Position = eye_matrix * position_matrix * scaling_matrix * sound_matrix * vec4(vertex_attrib, 1.0);
  red = (gl_Position[1]+0.9)/2.0;
  gl_PointSize = point_size;
}
示例#3
0
}
"""

# Here is the fragment shader
fragment_glsl = """
uniform sampler2D texture; // access the texture
varying vec2 texcoord_var;
void main(void) {
  gl_FragColor = texture2D(texture, texcoord_var);
}
"""

# The array spec: names and formats of the per-vertex attributes
#   vertex_attrib:2h  = two signed short integers  
#   color_attrib:3Bn  = three unsigned bytes, normalized (i.e. shader scales number 0..255 back to a float in range 0..1)
array_spec = glesutils.ArraySpec("vertex_attrib,texcoord_attrib:2h")

class MyWindow(glesutils.GameWindow):
    framerate = 20
    angle = 0

    def init(self):
        """All setup which requires the OpenGL context to be active."""
        
        # compile vertex and fragment shaders
        vertex_shader = glesutils.VertexShader(vertex_glsl)
        fragment_shader = glesutils.FragmentShader(fragment_glsl)
        # link them together into a program
        program = glesutils.Program(vertex_shader, fragment_shader)
        # set the background to RGBA = (1, 0, 0, 1) (solid red)
        glClearColor(1, 0, 0, 1)