Skip to content

Commit 84cf6ec

Browse files
Update pyrr and use pyrr.geometry.
Replace manual cube / quad creation with pyrr functions. Triangle is not replaced yet.
1 parent c05e294 commit 84cf6ec

File tree

4 files changed

+26
-117
lines changed

4 files changed

+26
-117
lines changed

pygly/examples/renderable_colour_cube.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,11 @@
66
from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram
77
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute
88
from pygly.vertex_array import VertexArray
9+
from pyrr import geometry
910

1011

11-
vertices = numpy.array(
12-
[
13-
(( 1.0, 1.0,-1.0),),
14-
((-1.0, 1.0,-1.0),),
15-
(( 1.0, 1.0, 1.0),),
16-
((-1.0, 1.0,-1.0),),
17-
((-1.0, 1.0, 1.0),),
18-
(( 1.0, 1.0, 1.0),),
19-
20-
(( 1.0,-1.0, 1.0),),
21-
((-1.0,-1.0, 1.0),),
22-
(( 1.0,-1.0,-1.0),),
23-
((-1.0,-1.0, 1.0),),
24-
((-1.0,-1.0,-1.0),),
25-
(( 1.0,-1.0,-1.0),),
26-
27-
(( 1.0, 1.0, 1.0),),
28-
((-1.0, 1.0, 1.0),),
29-
(( 1.0,-1.0, 1.0),),
30-
((-1.0, 1.0, 1.0),),
31-
((-1.0,-1.0, 1.0),),
32-
(( 1.0,-1.0, 1.0),),
33-
34-
(( 1.0,-1.0,-1.0),),
35-
((-1.0,-1.0,-1.0),),
36-
(( 1.0, 1.0,-1.0),),
37-
((-1.0,-1.0,-1.0),),
38-
((-1.0, 1.0,-1.0),),
39-
(( 1.0, 1.0,-1.0),),
40-
41-
((-1.0, 1.0, 1.0),),
42-
((-1.0, 1.0,-1.0),),
43-
((-1.0,-1.0, 1.0),),
44-
((-1.0, 1.0,-1.0),),
45-
((-1.0,-1.0,-1.0),),
46-
((-1.0,-1.0, 1.0),),
47-
48-
(( 1.0, 1.0,-1.0),),
49-
(( 1.0, 1.0, 1.0),),
50-
(( 1.0,-1.0,-1.0),),
51-
(( 1.0, 1.0, 1.0),),
52-
(( 1.0,-1.0, 1.0),),
53-
(( 1.0,-1.0,-1.0),),
54-
],
55-
dtype = [
56-
('position', 'float32', (3,)),
57-
]
58-
)
12+
vertices = geometry.create_cube(scale=(2.0,2.0,2.0), dtype='float32')
13+
vertices.dtype = [('position', 'float32', (3,)),]
5914

6015

6116
def create( core_profile = True ):

pygly/examples/renderable_cube.py

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,22 @@
66
from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram
77
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, ColourAttribute
88
from pygly.vertex_array import VertexArray
9-
10-
11-
vertices = numpy.array(
12-
[
13-
# X Y Z R G, B
14-
(( 1.0, 1.0,-1.0), (0.0, 1.0, 0.0)),
15-
((-1.0, 1.0,-1.0), (0.0, 1.0, 0.0)),
16-
(( 1.0, 1.0, 1.0), (0.0, 1.0, 0.0)),
17-
((-1.0, 1.0,-1.0), (0.0, 1.0, 0.0)),
18-
((-1.0, 1.0, 1.0), (0.0, 1.0, 0.0)),
19-
(( 1.0, 1.0, 1.0), (0.0, 1.0, 0.0)),
20-
21-
(( 1.0,-1.0, 1.0), (1.0, 0.5, 0.0)),
22-
((-1.0,-1.0, 1.0), (1.0, 0.5, 0.0)),
23-
(( 1.0,-1.0,-1.0), (1.0, 0.5, 0.0)),
24-
((-1.0,-1.0, 1.0), (1.0, 0.5, 0.0)),
25-
((-1.0,-1.0,-1.0), (1.0, 0.5, 0.0)),
26-
(( 1.0,-1.0,-1.0), (1.0, 0.5, 0.0)),
27-
28-
(( 1.0, 1.0, 1.0), (0.0, 0.0, 1.0)),
29-
((-1.0, 1.0, 1.0), (0.0, 0.0, 1.0)),
30-
(( 1.0,-1.0, 1.0), (0.0, 0.0, 1.0)),
31-
((-1.0, 1.0, 1.0), (0.0, 0.0, 1.0)),
32-
((-1.0,-1.0, 1.0), (0.0, 0.0, 1.0)),
33-
(( 1.0,-1.0, 1.0), (0.0, 0.0, 1.0)),
34-
35-
(( 1.0,-1.0,-1.0), (1.0, 0.0, 1.0)),
36-
((-1.0,-1.0,-1.0), (1.0, 0.0, 1.0)),
37-
(( 1.0, 1.0,-1.0), (1.0, 0.0, 1.0)),
38-
((-1.0,-1.0,-1.0), (1.0, 0.0, 1.0)),
39-
((-1.0, 1.0,-1.0), (1.0, 0.0, 1.0)),
40-
(( 1.0, 1.0,-1.0), (1.0, 0.0, 1.0)),
41-
42-
((-1.0, 1.0, 1.0), (1.0, 1.0, 0.0)),
43-
((-1.0, 1.0,-1.0), (1.0, 1.0, 0.0)),
44-
((-1.0,-1.0, 1.0), (1.0, 1.0, 0.0)),
45-
((-1.0, 1.0,-1.0), (1.0, 1.0, 0.0)),
46-
((-1.0,-1.0,-1.0), (1.0, 1.0, 0.0)),
47-
((-1.0,-1.0, 1.0), (1.0, 1.0, 0.0)),
48-
49-
(( 1.0, 1.0,-1.0), (1.0, 0.0, 0.0)),
50-
(( 1.0, 1.0, 1.0), (1.0, 0.0, 0.0)),
51-
(( 1.0,-1.0,-1.0), (1.0, 0.0, 0.0)),
52-
(( 1.0, 1.0, 1.0), (1.0, 0.0, 0.0)),
53-
(( 1.0,-1.0, 1.0), (1.0, 0.0, 0.0)),
54-
(( 1.0,-1.0,-1.0), (1.0, 0.0, 0.0)),
55-
],
56-
dtype = [
57-
('position', 'float32', (3,)),
58-
('colour', 'float32', (3,)),
59-
]
60-
)
9+
from pyrr import geometry
10+
11+
12+
rgba=(
13+
(0.0, 1.0, 0.0,),
14+
(1.0, 0.5, 0.0,),
15+
(0.0, 0.0, 1.0,),
16+
(1.0, 0.0, 1.0,),
17+
(1.0, 1.0, 0.0,),
18+
(1.0, 0.0, 0.0,),
19+
)
20+
vertices = geometry.create_cube(scale=(2.0,2.0,2.0), rgba=rgba, dtype='float32')
21+
vertices.dtype = [
22+
('position', 'float32', (3,)),
23+
('colour', 'float32', (3,)),
24+
]
6125

6226

6327
def create( core_profile = True ):

pygly/examples/renderable_textured_quad.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@
66
from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram
77
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, TextureCoordAttribute
88
from pygly.vertex_array import VertexArray
9+
from pyrr import geometry
910

1011

11-
# create a triangle
12-
vertices = numpy.array(
13-
[
14-
# X Y Z U V
15-
(( 1.0, 1.0, 0.0), (1.0, 1.0)),
16-
((-1.0, 1.0, 0.0), (0.0, 1.0)),
17-
(( 1.0,-1.0, 0.0), (1.0, 0.0)),
18-
((-1.0, 1.0, 0.0), (0.0, 1.0)),
19-
((-1.0,-1.0, 0.0), (0.0, 0.0)),
20-
(( 1.0,-1.0, 0.0), (1.0, 0.0)),
21-
],
22-
dtype = [
23-
('position', 'float32', (3,)),
24-
('texture_coord', 'float32', (2,)),
25-
]
26-
)
12+
vertices = geometry.create_quad(scale=(5.0,5.0), st=True, dtype='float32')
13+
vertices.dtype = [
14+
('position', 'float32', (3,)),
15+
('texture_coord', 'float32', (2,)),
16+
]
2717

2818

2919
def create( core_profile = True ):

0 commit comments

Comments
 (0)