Skip to content

Commit 7149485

Browse files
committed
Started markers chapter
1 parent fa570c2 commit 7149485

37 files changed

+1034
-134
lines changed

08-markers.rst

Lines changed: 420 additions & 37 deletions
Large diffs are not rendered by default.

book.html

Lines changed: 442 additions & 96 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.

code/chapter-08/marker.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -----------------------------------------------------------------------------
2+
# Python & OpenGL for Scientific Visualization
3+
# www.labri.fr/perso/nrougier/python+opengl
4+
# Copyright (c) 2017, Nicolas P. Rougier
5+
# Distributed under the 2-Clause BSD License.
6+
# -----------------------------------------------------------------------------
7+
import numpy as np
8+
from glumpy import app, gl, gloo
9+
from glumpy.transforms import Position, OrthographicProjection, PanZoom
10+
11+
# Create window
12+
window = app.Window(width=2*512, height=512, color=(1,1,1,1))
13+
14+
# What to draw when necessary
15+
@window.event
16+
def on_draw(dt):
17+
window.clear()
18+
program.draw(gl.GL_POINTS)
19+
program['orientation'][-1] += np.pi/1024.0
20+
21+
# Setup some markers
22+
n = 500+1
23+
data = np.zeros(n, dtype=[('position', np.float32, 2),
24+
('fg_color', np.float32, 4),
25+
('bg_color', np.float32, 4),
26+
('size', np.float32, 1),
27+
('orientation', np.float32, 1),
28+
('linewidth', np.float32, 1)])
29+
data = data.view(gloo.VertexBuffer)
30+
data['linewidth'] = 1
31+
data['fg_color'] = 0, 0, 0, 1
32+
data['bg_color'] = 1, 1, 1, 0
33+
data['orientation'] = 0
34+
radius, theta, dtheta = 250.0, 0.0, 5.5 / 180.0 * np.pi
35+
for i in range(500):
36+
theta += dtheta
37+
x = 256 + radius * np.cos(theta)
38+
y = 256 + radius * np.sin(theta)
39+
r = 10.0 - i * 0.02
40+
radius -= 0.45
41+
data['orientation'][i] = theta - np.pi/2
42+
data['position'][i] = x, y
43+
data['size'][i] = 2 * r
44+
data['linewidth'][i] = 1
45+
46+
data['position'][-1] = 512+256, 256
47+
data['size'][-1] = 512/np.sqrt(2)
48+
data['linewidth'][-1] = 3.0
49+
data['fg_color'][-1] = 0, 0, 0, 1
50+
data['bg_color'][-1] = .95, .95, .95, 1
51+
data['orientation'][-1] = 0
52+
53+
program = gloo.Program("markers/marker.vert", "markers/marker.frag")
54+
program.bind(data)
55+
program['antialias'] = 1.00
56+
57+
# <marker> : "arrow", "asterisk", "chevron", "clover", "club",
58+
# "cross", "diamond", "disc", "ellipse", "hbar",
59+
# "heart", "infinity", "pin", "ring", "spade",
60+
# "square", "tag", "triangle", "vbar"
61+
program['marker'] = "asterisk"
62+
63+
# <paint> : "stroke", "filled" or "outline"
64+
program['paint'] = "outline"
65+
66+
transform = OrthographicProjection(Position("position"))
67+
program['transform'] = transform
68+
window.attach(transform)
69+
70+
app.run()

code/hardware-msaa.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -----------------------------------------------------------------------------
2+
# Python & OpenGL for Scientific Visualization
3+
# www.labri.fr/perso/nrougier/python+opengl
4+
# Copyright (c) 2017, Nicolas P. Rougier
5+
# Distributed under the 2-Clause BSD License.
6+
# -----------------------------------------------------------------------------
7+
import numpy as np
8+
from glumpy import app, gloo, gl
9+
10+
vertex = """
11+
uniform vec2 resolution;
12+
// attribute vec2 position;
13+
in vec2 position;
14+
void main()
15+
{ gl_Position = vec4(2.0*position/resolution-1.0, 0.0, 1.0); }
16+
"""
17+
18+
fragment = """
19+
out vec4 color;
20+
void main() { color = vec4(vec3(0.0), 1.0); }
21+
// void main() { gl_FragColor = vec4(vec3(0.0), 1.0); }
22+
"""
23+
24+
config = app.configuration.Configuration()
25+
config.samples = 6
26+
config.major_version = 3
27+
config.minor_version = 2
28+
config.profile = "core"
29+
GLSL_version = "150"
30+
window = app.Window(32, 8, color=(1,1,1,1), config=config)
31+
32+
triangle = gloo.Program(vertex, fragment, version=GLSL_version)
33+
V = np.zeros(3, dtype=[("position", np.float32,2)])
34+
V["position"] = (1.,3.), (7.,7.), (30., 1.)
35+
V = V.view(gloo.VertexArray)
36+
triangle.bind(V)
37+
38+
@window.event
39+
def on_resize(width, height):
40+
triangle["resolution"] = width, height
41+
42+
@window.event
43+
def on_init():
44+
gl.glEnable(gl.GL_MULTISAMPLE)
45+
pass
46+
47+
@window.event
48+
def on_draw(dt):
49+
window.clear()
50+
triangle.draw(gl.GL_TRIANGLE_STRIP)
51+
52+
53+
for i in range(window.config.samples):
54+
print(gl.glGetMultisamplefv(gl.GL_SAMPLE_POSITION, i))
55+
56+
app.run()

0 commit comments

Comments
 (0)