Skip to content

Commit 54ae45c

Browse files
committed
Started relocation of code, images & movies
1 parent c8ab4c8 commit 54ae45c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+516
-1232
lines changed

01-preface.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ If you want to contribute to this book, you can:
127127
* Suggest improvements (https://github.com/rougier/python+opengl/pulls)
128128
* Correct English (https://github.com/rougier/python+opengl/issues)
129129
* Star the project (https://github.com/rougier/python+opengl)
130-
* Suggest a more responvise design for the HTML Book
131-
* Design a nice latex template for a PDF version
130+
* Suggest a more responsive design for the HTML Book
131+
* Spread the word about this book (Reddit, Hacker News, etc.)
132132

133133
Publishing
134134
++++++++++
@@ -158,6 +158,17 @@ Alike 4.0 International License <https://creativecommons.org/licenses/by-nc-sa/4
158158

159159
The licensor cannot revoke these freedoms as long as you follow the license terms.
160160

161+
Under the following terms:
162+
163+
* **Attribution** — You must give appropriate credit, provide a link to the
164+
license, and indicate if changes were made. You may do so in any reasonable
165+
manner, but not in any way that suggests the licensor endorses you or your
166+
use.
167+
* **NonCommercial** — You may not use the material for commercial purposes.
168+
* **ShareAlike** — If you remix, transform, or build upon the material, you
169+
must distribute your contributions under the same license as the original.
170+
171+
161172
Code
162173
++++
163174

@@ -177,7 +188,7 @@ mainly) a researcher with several students to supervise, researches to do,
177188
grants to write, talks to prepare, etc.
178189

179190
Consequently, if you really want to have a PDF version, you'll have to
180-
explicitely express your interest by contributing a small amount of
191+
explicitly express your interest by contributing a small amount of
181192
money. Then,
182193

183194
* if the total reach **5,000 euros**, I'll produce the PDF
@@ -188,7 +199,7 @@ reached. In such case, consider your payment as a donation to the online
188199
version. If you find this unfair, remember you have the choice to give or not
189200
and the online version is free and open source...
190201

191-
.. image:: crowdfunding.png
202+
.. image:: images/chapter-01/crowdfunding.png
192203
:width: 100%
193204

194205

02-introduction.rst

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OpenGL is 25 years old! Since the first release in 1992, a lot has happened
2121
(and is still happening actually, with the newly released Vulkan_ API and the
2222
4.6 GL release) and consequently, before diving into the book, it is important
2323
to understand OpenGL API evolution over the years. If the first API (1.xx) has
24-
not changed too much in the first twelve years, a big change occured in 2004
24+
not changed too much in the first twelve years, a big change occurred in 2004
2525
with the introduction of the dynamic pipeline (OpenGL 2.x), i.e. the use of
2626
shaders that allow to have direct access to the GPU. Before this version,
2727
OpenGL was using a fixed pipeline that made it easy to rapidly prototype some
@@ -130,8 +130,8 @@ API).
130130
.. note::
131131

132132
The number of functions and constants have been computed using the
133-
`<code/registry.py>`_ program that parses the gl.xml_ file that defines the
134-
OpenGL and OpenGL API Registry
133+
`<code/chapter-02/registry.py>`_ program that parses the gl.xml_ file that
134+
defines the OpenGL and OpenGL API Registry
135135

136136
======== ========= ========= === ============ ========= =========
137137
Version Constants Functions Version Constants Functions
@@ -167,7 +167,7 @@ The graphic pipeline
167167
.. Note::
168168

169169
The shader language is called glsl. There are many versions that goes from 1.0
170-
to 1.5 and subsequents version get the number of OpenGL version. Last version
170+
to 1.5 and subsequent version get the number of OpenGL version. Last version
171171
is 4.6 (June 2017).
172172

173173
If you want to understand modern OpenGL, you have to understand the graphic
@@ -178,7 +178,7 @@ depending on the version of OpenGL you're using), they will act at different
178178
stage of the rendering pipeline. To simplify this tutorial, we'll use only
179179
**vertex** and **fragment** shaders as shown below:
180180

181-
.. image:: data/gl-pipeline.png
181+
.. image:: images/chapter-02/gl-pipeline.png
182182
:width: 100%
183183

184184
A vertex shader acts on vertices and is supposed to output the vertex
@@ -207,7 +207,7 @@ output the null vertex (`gl_Position` is a special variable) while the second
207207
will only output the black color for any fragment (`gl_FragColor` is also a
208208
special variable). We'll see later how to make them to do more useful things.
209209

210-
One question remains: when are those shaders exectuted exactly ? The vertex
210+
One question remains: when are those shaders executed exactly ? The vertex
211211
shader is executed for each vertex that is given to the rendering pipeline
212212
(we'll see what does that mean exactly later) and the fragment shader is
213213
executed on each fragment (= pixel) that is generated after the vertex
@@ -246,7 +246,7 @@ structured array using numpy_:
246246
247247
We just created a CPU buffer with 4 vertices, each of them having a
248248
`position` (3 floats for x,y,z coordinates) and a `color` (4 floats for
249-
red, blue, green and alpha channels). Note that we explicitely chose to have 3
249+
red, blue, green and alpha channels). Note that we explicitly chose to have 3
250250
coordinates for `position` but we may have chosen to have only 2 if were to
251251
work in two-dimensions. Same holds true for `color`. We could have used
252252
only 3 channels (r,g,b) if we did not want to use transparency. This would save
@@ -263,8 +263,8 @@ using 2 floats for position and 4 floats for color:
263263

264264
.. code:: python
265265
266-
data = numpy.zeros(4, dtype = [ ("position", np.float32, 2),
267-
("color", np.float32, 4)] )
266+
data = numpy.zeros(4, dtype = [ ("position", np.float32, 2),
267+
("color", np.float32, 4)] )
268268
269269
We need to tell the vertex shader that it will have to handle vertices where a
270270
position is a tuple of 2 floats and color is a tuple of 4 floats. This is
@@ -273,19 +273,19 @@ vertex shader:
273273

274274
.. code:: glsl
275275
276-
attribute vec2 position;
277-
attribute vec4 color;
278-
void main()
279-
{
280-
gl_Position = vec4(position, 0.0, 1.0);
281-
}
276+
attribute vec2 position;
277+
attribute vec4 color;
278+
void main()
279+
{
280+
gl_Position = vec4(position, 0.0, 1.0);
281+
}
282282
283283
This vertex shader now expects a vertex to possess 2 attributes, one named
284284
`position` and one named `color` with specified types (vec3 means tuple of
285285
3 floats and vec4 means tuple of 4 floats). It is important to note that even
286286
if we labeled the first attribute `position`, this attribute is not yet bound
287287
to the actual `position` in the numpy array. We'll need to do it explicitly
288-
at some point in our program and there is no omagic that will bind the numpy
288+
at some point in our program and there is no magic that will bind the numpy
289289
array field to the right attribute, you'll have to do it yourself, but we'll
290290
see that later.
291291

@@ -296,44 +296,44 @@ we would thus write:
296296

297297
.. code:: glsl
298298
299-
uniform float scale;
300-
attribute vec2 position;
301-
attribute vec4 color;
302-
void main()
303-
{
304-
gl_Position = vec4(position*scale, 0.0, 1.0);
305-
}
299+
uniform float scale;
300+
attribute vec2 position;
301+
attribute vec4 color;
302+
void main()
303+
{
304+
gl_Position = vec4(position*scale, 0.0, 1.0);
305+
}
306306
307307
Last type is the varying type that is used to pass information between the
308308
vertex stage and the fragment stage. So let us suppose (again) we want to pass
309309
the vertex color to the fragment shader, we now write:
310310

311311
.. code:: glsl
312312
313-
uniform float scale;
314-
attribute vec2 position;
315-
attribute vec4 color;
316-
varying vec4 v_color;
313+
uniform float scale;
314+
attribute vec2 position;
315+
attribute vec4 color;
316+
varying vec4 v_color;
317317
318-
void main()
319-
{
320-
gl_Position = vec4(position*scale, 0.0, 1.0);
321-
v_color = color;
322-
}
318+
void main()
319+
{
320+
gl_Position = vec4(position*scale, 0.0, 1.0);
321+
v_color = color;
322+
}
323323
324324
and then in the fragment shader, we write:
325325

326326
.. code:: glsl
327327
328-
varying vec4 v_color;
328+
varying vec4 v_color;
329329
330-
void main()
331-
{
332-
gl_FragColor = v_color;
333-
}
330+
void main()
331+
{
332+
gl_FragColor = v_color;
333+
}
334334
335335
The question is what is the value of `v_color` inside the fragment shader ?
336-
If you look at the figure that introduced the gl pipleline, we have 3 vertices
336+
If you look at the figure that introduced the gl pipeline, we have 3 vertices
337337
and 21 fragments. What is the color of each individual fragment ?
338338

339339
The answer is *the interpolation of all 3 vertices color*. This interpolation
@@ -350,7 +350,7 @@ State of the union
350350
Last, but not least, we need to access the OpenGL library from within Python
351351
and we have mostly two solutions at our disposal. Either we use pure bindings
352352
and we have to program everything (see next chapter) or we use an engine that
353-
provide a lot oc convenient functions that ease the development. We'll first
353+
provide a lot of convenient functions that ease the development. We'll first
354354
use the PyOpenGL bindings before using the glumpy_ library that offers a tight
355355
integration with numpy.
356356

@@ -476,6 +476,6 @@ Libraries
476476
.. _gl.xml:
477477
https://github.com/KhronosGroup/OpenGL-Registry/blob/master/xml/gl.xml
478478
.. _registry.py:
479-
code/registry.py
479+
code/chapter-02/registry.py
480480

481481
.. ----------------------------------------------------------------------------

03-quickstart.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Quickstart
32
===============================================================================
43

@@ -29,7 +28,7 @@ simple colored quad (i.e. a red square).
2928
Normalize Device Coordinates
3029
++++++++++++++++++++++++++++
3130

32-
.. figure:: data/NDC.png
31+
.. figure:: images/chapter-03/NDC.png
3332
:figwidth: 40%
3433
:figclass: left
3534

@@ -58,7 +57,7 @@ some problems, especially when you're dealing with the mouse pointer whose
5857
Triangulation
5958
+++++++++++++
6059

61-
.. figure:: data/triangulation.png
60+
.. figure:: images/chapter-03/triangulation.png
6261
:figwidth: 35%
6362
:figclass: left
6463

@@ -104,7 +103,7 @@ is exactly what we need to tell OpenGL.
104103
GL Primitives
105104
+++++++++++++
106105

107-
.. figure:: data/gl-primitives.png
106+
.. figure:: images/chapter-03/gl-primitives.png
108107
:figwidth: 40%
109108
:figclass: left
110109

@@ -143,7 +142,7 @@ structure.
143142
Interpolation
144143
+++++++++++++
145144

146-
.. figure:: data/interpolation.png
145+
.. figure:: images/chapter-03/interpolation.png
147146
:figwidth: 40%
148147
:figclass: left
149148

@@ -457,7 +456,7 @@ We're done, we can now rewrite the display function:
457456
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
458457
glut.glutSwapBuffers()
459458
460-
.. figure:: data/glumpy-quad-solid.png
459+
.. figure:: images/chapter-03/glumpy-quad-solid.png
461460
:figwidth: 30%
462461
:figclass: left
463462

@@ -469,7 +468,7 @@ We're done, we can now rewrite the display function:
469468
The `0,4` arguments in the `glDrawArrays` tells OpenGL we want to display 4
470469
vertices from our current active buffer and we start at vertex 0. You should
471470
obtain the figure on the right with the same red (boring) color. The whole
472-
source ia available from `<code/glut-quad-solid.py>`_.
471+
source ia available from `<code/chapter-03/glut-quad-solid.py>`_.
473472

474473
All these operations are necessary for displaying a single colored quad on
475474
screen and complexity can escalate pretty badly if you add more objects,
@@ -483,7 +482,7 @@ Python applications.
483482
Uniform color
484483
+++++++++++++
485484

486-
.. figure:: data/glumpy-quad-uniform-color.png
485+
.. figure:: images/chapter-03/glumpy-quad-uniform-color.png
487486
:figwidth: 30%
488487
:figclass: left
489488

@@ -527,7 +526,7 @@ Varying color
527526
+++++++++++++
528527

529528

530-
.. figure:: data/glumpy-quad-varying-color.png
529+
.. figure:: images/chapter-03/glumpy-quad-varying-color.png
531530
:figwidth: 30%
532531
:figclass: left
533532

@@ -812,7 +811,7 @@ the rendering is now a matter of writing the proper shader. We'll get a first
812811
taste in the three exercises below but we'll see much more powerful shader
813812
tricks in the next chapters.
814813

815-
.. figure:: data/quad-scale.mp4
814+
.. figure:: movies/chapter-03/quad-scale.mp4
816815
:loop:
817816
:autoplay:
818817
:controls:
@@ -831,11 +830,11 @@ order for the quad to be animated and to scale with time as shown in the figure
831830
on the right. You will need to update the scale factor within the Python
832831
program, for example in the `draw` function.
833832

834-
Solution: `<code/quad-scale.py>`_
833+
Solution: `<code/chapter-03/quad-scale.py>`_
835834

836835
----
837836

838-
.. figure:: data/quad-rotate.mp4
837+
.. figure:: movies/chapter-03/quad-rotate.mp4
839838
:loop:
840839
:autoplay:
841840
:controls:

04-maths.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Basic Mathematics
32
===============================================================================
43

@@ -49,7 +48,7 @@ Let us consider for example a simple set of point `[-1.0, -0.5, 0.0, +0.5,
4948
is discared and won't be visible into the final projection) The question now is
5049
how do we project the points onto the screen?
5150

52-
.. figure:: data/1D-H-Coordinates.png
51+
.. figure:: images/chapter-04/1D-H-Coordinates.png
5352
:figwidth: 50%
5453
:figclass: right
5554

@@ -70,7 +69,7 @@ in our unidimensional Euclidean space. From this conversion, we can see
7069
immediately that there exist actually an infinite set of homogenous coordinates
7170
that correspond to a single Cartesian coordinate as illustrated on the figure.
7271

73-
.. figure:: data/1D-Projection.png
72+
.. figure:: images/chapter-04/1D-Projection.png
7473
:figwidth: 100%
7574

7675
Figure
@@ -135,7 +134,7 @@ by Sam Hocevar:
135134
Transformations
136135
-------------------------------------------------------------------------------
137136

138-
.. figure:: data/composition.png
137+
.. figure:: images/chapter-04/composition.png
139138
:figwidth: 50%
140139
:figclass: right
141140

0 commit comments

Comments
 (0)