示例#1
0
def timer(fps):
    global clock
    clock += 0.001 * 1000.0 / fps
    program['theta'] = clock
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()


# Glut init
# --------------------------------------
glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Hello world!')
glut.glutReshapeWindow(512, 512)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutTimerFunc(1000 / 60, timer, 60)

# Build program & data
# ----------------------------------------
program = Program(vertex, fragment, count=4)
program['color'] = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1), (1, 1, 0, 1)]
program['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
clock = 0

# Enter mainloop
# --------------------------------------
glut.glutMainLoop()
示例#2
0
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutPassiveMotionFunc(on_passive_motion)
glut.glutTimerFunc(1000 / 60, timer, 60)

# Build data
# --------------------------------------
n = 500
data = np.zeros(n, [('a_position', np.float32, 2),
                    ('a_fg_color', np.float32, 4), ('a_size', np.float32, 1)])
index = 0

# Build program
# --------------------------------------
program = Program(vertex, fragment)
vdata = VertexBuffer(data)
program.bind(vdata)
program['u_antialias'] = 1.00
program['u_linewidth'] = 1.00

# Build view, model, projection
# --------------------------------------
program['u_model'] = np.eye(4, dtype=np.float32)
program['u_view'] = np.eye(4, dtype=np.float32)

# OpenGL initalization
# --------------------------------------
gl.glClearColor(1.0, 1.0, 1.0, 1.0)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glEnable(gl.GL_BLEND)
示例#3
0
# --------------------------------------
vertices, indices, _ = cube()
vertices = VertexBuffer(vertices)
indices = IndexBuffer(indices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
translate(view, 0, 0, -5)
normal = np.array(np.matrix(np.dot(view, model)).I.T)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)
program["light_position"] = 2, 2, 2
program["light_intensity"] = 1, 1, 1
program["u_model"] = model
program["u_view"] = view
program["u_normal"] = normal
phi, theta = 0, 0

# OpenGL initalization
# --------------------------------------
gl.glClearColor(.3, .3, .35, 1)
gl.glEnable(gl.GL_DEPTH_TEST)

# Start
# --------------------------------------
示例#4
0
    if key == '\033': sys.exit()


# Glut init
# --------------------------------------
glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Colormap interpolation + contours')
glut.glutReshapeWindow(512, 512)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)

# Build program
# --------------------------------------
program = Program(vertex, fragment, 4)
program['a_position'] = (-1, -1), (-1, +1), (+1, -1), (+1, +1)
program['a_texcoord'] = (0, 0), (0, +1), (+1, 0), (+1, +1)


# Build data
# --------------------------------------
def func3(x, y):
    return (1 - x / 2 + x**5 + y**3) * np.exp(-x**2 - y**2)


x = np.linspace(-3.0, 3.0, 256).astype(np.float32)
y = np.linspace(-3.0, 3.0, 256).astype(np.float32)
X, Y = np.meshgrid(x, y)
Z = func3(X, Y)
program['u_data'] = (Z - Z.min()) / (Z.max() - Z.min())
示例#5
0
# --------------------------------------
V = np.zeros(8, [("position", np.float32, 3),
                 ("color",    np.float32, 4)])
V["position"] = [[ 1, 1, 1], [-1, 1, 1], [-1,-1, 1], [ 1,-1, 1],
                 [ 1,-1,-1], [ 1, 1,-1], [-1, 1,-1], [-1,-1,-1]]
V["color"]    = [[0, 1, 1, 1], [0, 0, 1, 1], [0, 0, 0, 1], [0, 1, 0, 1],
                 [1, 1, 0, 1], [1, 1, 1, 1], [1, 0, 1, 1], [1, 0, 0, 1]]
vertices = VertexBuffer(V)

I = [0,1,2, 0,2,3,  0,3,4, 0,4,5,  0,5,6, 0,6,1,
     1,6,7, 1,7,2,  7,4,3, 7,3,2,  4,7,6, 4,6,5]
indices = IndexBuffer(I)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4,dtype=np.float32)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
translate(view, 0,0,-5)
program['model'] = model
program['view'] = view
phi, theta = 0,0

# OpenGL initalization
# --------------------------------------
gl.glClearColor(1,1,1,1)
示例#6
0
glut.glutKeyboardFunc(keyboard )
glut.glutDisplayFunc(display)
glut.glutPassiveMotionFunc(on_passive_motion)
glut.glutTimerFunc(1000/60, timer, 60)

# Build data
# --------------------------------------
n = 500
data = np.zeros(n, [ ('a_position', np.float32, 2),
                     ('a_fg_color', np.float32, 4),
                     ('a_size',     np.float32, 1)])
index = 0

# Build program
# --------------------------------------
program = Program(vertex, fragment)
vdata = VertexBuffer(data)
program.bind(vdata)
program['u_antialias'] = 1.00
program['u_linewidth'] = 1.00

# Build view, model, projection
# --------------------------------------
program['u_model'] = np.eye(4,dtype=np.float32)
program['u_view'] = np.eye(4,dtype=np.float32)

# OpenGL initalization
# --------------------------------------
gl.glClearColor(1.0, 1.0, 1.0, 1.0)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glEnable(gl.GL_BLEND)
示例#7
0
# Build cloud data
# --------------------------------------
n = 100000
data = np.zeros(n, [ ('a_position', np.float32, 3),
                     ('a_bg_color', np.float32, 4),
                     ('a_fg_color', np.float32, 4),
                     ('a_size',     np.float32, 1)])
data['a_position'] = 0.45 * np.random.randn(n,3)
data['a_bg_color'] = np.random.uniform(0.75,1.00,(n,4))
data['a_fg_color'] = 0,0,0,.5
data['a_size'] = np.random.uniform(5,10,n)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(VertexBuffer(data))
program['u_linewidth'] = 0.75
program['u_antialias'] = 1.00

# Build view, model, projection
# --------------------------------------
view = np.eye(4,dtype=np.float32)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
translate(view, 0, 0, -5)
program['u_model'] = model
program['u_view'] = view
phi, theta = 0,0

# OpenGL initalization
示例#8
0
glut.glutDisplayFunc(display)
glut.glutTimerFunc(1000/60, timer, 60)

# Build cloud data
# --------------------------------------
n = 100000
data = np.zeros(n, [ ('a_position', np.float32, 3),
                     ('a_color',    np.float32, 3),
                     ('a_radius',   np.float32, 1)])
data['a_position'] = np.random.randn(n,3) + (0,0,0)
data['a_color'] = np.random.uniform(0.75,1.00,(n,3))
data['a_radius'] = np.random.uniform(5,10,n)/100.

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(VertexBuffer(data))
program['u_light_position'] = 2,2,2


# Build view, model, projection
# --------------------------------------
view = np.eye(4,dtype=np.float32)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
translate(view, 0, 0,-10)
#view = look_at((4.0,3.0,1.0), (0.0,0.0,0.0), (0.0,0.0,1.0))
program['u_model'] = model
program['u_view'] = view
phi, theta = 0,0