1- |pypi | |travis |
1+ |pypi | |travis | | rtd |
22
33demosys-py
44==========
@@ -13,18 +13,22 @@ design of this version is heavily inspired by the
1313| |screenshot1 | | |screenshot2 | |
1414+-----------------+-----------------+
1515
16- We only support OpenGL 4.1+ core profiles (no backwards compatibility).
16+ We only support OpenGL 3.3+ forward compatible core profiles (no backwards compatibility).
1717
1818This was originally made for for non-interactive real time graphics
1919combined with music ("real time music videos"). It's made for people who
2020enjoy playing around with modern OpenGL without having to spend lots of
2121time creating all the tooling to get things up and running.
2222
23- demosys-py is now on PyPI
23+ If you are not a fan of using a framework, you can create your own context
24+ and just use the classes in ``demosys.opengl ``. These will give you fairly
25+ straight forward ways to use VAOs, Shaders, Textures and FBOs.
2426
25- ::
27+ Documentation
28+ -------------
2629
27- pip install demosys-py
30+ Project documentation can be found at readthedocs _. Optionally you can
31+ build your own docs from the ``docs `` directory.
2832
2933Contributing
3034------------
@@ -37,281 +41,6 @@ This is supposed to be a fun project.
3741Also check out the `TODO list <TODO.md >`__. Take a stab on what of the
3842features or documentation or suggest new entries.
3943
40- Running the damned thing
41- ------------------------
42-
43- - First of all make sure you have python3 installed
44- - Install GLFW binaries for your OS from your favorite package manger or download it from http://www.glfw.org/
45- - If you want working music you will also need to install SDL
46-
47- Let's clone the testdemo project.
48-
49- ::
50-
51- git clone https://github.com/Contraz/demosys-py-test
52- cd demosys-py-test
53- python3 -m virtualenv env
54- source env/bin/activate
55- pip install -r requirements.txt
56- ./manage.py runeffect testdemo.cube
57-
58- This runs the effect ``cube `` in the ``testdemo `` package.
59-
60- Controls
61- ========
62-
63- - Currently you can control the camera with ``A ``, ``W ``, ``S `` and ``D ``.
64- ``Q `` and ``E `` for y axis movements
65- - Standard yaw/pitch camera rotation with mouse
66- - ``ESC `` for exit
67- - ``SPACE `` for pause
68- - ``X `` for taking ``png `` screenshot
69-
70- I just want to see an example!
71- ==============================
72-
73- Ok, ok! You can find examples in the testdemo _.
74-
75- To create a project with an effect we can use the convenient demosys-admin command.
76-
77- .. code :: shell
78-
79- demosys-admin createproject testdemo
80- cd testdemo
81- demosys-admin createeffect cube
82-
83- We should now have the following stucture with a working effect we can actually run.
84-
85- ::
86-
87- testdemo
88- ├── cube
89- │ ├── effect.py
90- │ ├── shaders
91- │ │ └── cube
92- │ │ ├── cube.glsl
93- │ └── textures
94- │ └── cube
95- │ └── texture.png
96-
97- The effect.py generated looks something like this:
98-
99- .. code :: python
100-
101- from demosys.effects import effect
102- from demosys.opengl import geometry, FBO
103- from OpenGL import GL
104-
105- class CubeEffect (effect .Effect ):
106- """ Rotating cube with UVs and normals"""
107- def __init__ (self ):
108- self .shader = self .get_shader(' cube/cube.glsl' )
109- self .texture = self .get_texture(' cube/texture.png' )
110- self .cube = geometry.cube(2.0 , 2.0 , 2.0 )
111-
112- @effect.bind_target
113- def draw (self , time , frametime , target ):
114- GL .glEnable(GL .GL_DEPTH_TEST )
115-
116- # Cheater methods in base class for lazyness
117- mv_m = self .create_transformation(rotation = (time * 1.2 , time * 2.1 , time * 0.25 ),
118- translation = (0.0 , 0.0 , - 8.0 ))
119- normal_m = self .create_normal_matrix(mv_m)
120- proj_m = self .create_projection(fov = 60.0 )
121-
122- # The VAO and shader will do a a little dance and agree on attributes
123- with self .cube.bind(self .shader) as shader:
124- shader.uniform_mat4(" m_proj" , proj_m)
125- shader.uniform_mat4(" m_mv" , mv_m)
126- shader.uniform_mat3(" m_normal" , normal_m)
127- shader.uniform_sampler_2d(0 , " texture0" , self .texture)
128- self .cube.draw()
129-
130- There you go.
131-
132- - Shaders and textures can be easily loaded by using the ``get_texture `` and
133- ``get_shader `` method inherited from ``Effect ``.
134- - The ``cube `` objects is a ``VAO `` that you bind supplying the shader and the system
135- will figure out the attribute mapping.
136- - Please look in the ``demosys.opengl.geometry `` module for the valid attribute names and
137- look at shaders in the testdemo _.
138- - You currently define vertex,
139- fragment and geometry shader in one glsl file separated by
140- preprocessors.
141- - Effects not defined in the ``settings.py `` module will not run.
142-
143- That should give you an idea..
144-
145- Longer Introduction
146- -------------------
147-
148- Anything we draw to the screen must be implemented as an ``Effect ``. If
149- that effect is one or multiple things is entirely up to you. An effect
150- is an individual package/directory containing an ``effect.py `` module.
151- This package can also contain a ``shaders `` and ``textures `` directory
152- that demosys will automatically find and load resources from. See the
153- testdemo _.
154-
155- Explore the testdemo _ project, and you'll get the point.
156-
157- Some babble about the current state of the project:
158-
159- - All geometry must be defined using VAOs. There's a very convenient VAO
160- class for this already making it quick and easy to create them. Look at
161- the ``demosys.opengl.geometry `` module for examples.
162- - We support vertex,
163- fragment and geometry shaders for now. A program must currently be
164- written in one single ``.glsl `` file separating the shaders with
165- preprocessors. See existing shaders in testdemo _.
166- - The Shader class will inspect the linked shader and cache all attributes
167- and uniforms in local dictionaries. This means all ``uniform* ``-setters use
168- the name of the uniform instead of the location. Location is resolved
169- internally in the object/class.
170- - The VAOs ``bind(..) `` requires you to pass in a shader. This is because
171- the VAO will automatically adapt to the attributes in your shader.
172- During the VAO creation you need to make the name mapping to the attribute
173- name. If you have a VAO with positions, normals, uvs and tangents and pass
174- in a shader that only use position (or any other combination of attributes
175- in the VAO); the VAO class will on-the-fly generate a version internally
176- with only positions.
177- - We only support 2D textures at the moment loaded with PIL/Pillow, but
178- this is trivial to extend.
179- - Resource loading is supported in the ``Effect `` class itself. In ``__init__() ``
180- you can fetch resources using for example ``self.get_shader `` or\ ``self.get_texture ``.
181- This will return a lazy object that will be populated after the loading
182- stage is done.
183- - Resources shared between effects can be put outside effect packages
184- inside your project directory. For example in ``testdemo/resources/shaders ``
185- and ``testdemo/resources/textures ``. Make sure you add those paths in the
186- settings file.
187- - We don't have any scene/mesh loaders. You can hack something in yourself
188- for now or just stick to or extend the ``geometry `` module. - We try to
189- do as much validation as possible and give useful feedback when something
190- goes wrong.
191- - The ``time `` value passed to the effects ``draw `` method is the current
192- duration in the playing music. If no music is loaded, a dummy timer is used.
193-
194- Settings
195- --------
196-
197- The ``settings.py `` file must be present in your project and contains
198- (you guessed right!) settings for the framework. This is pretty much
199- identical to Django.
200-
201- OPENGL
202- ~~~~~~
203-
204- Using these values you are sure it will run on all platforms. OS X only
205- support forward compatible core contexts. This will bump you to the
206- latest version you drivers support.
207-
208- .. code :: python
209-
210- OPENGL = {
211- " version" : (4 , 1 ),
212- " profile" : " core" ,
213- " forward_compat" : True ,
214- }
215-
216- WINDOW
217- ~~~~~~
218-
219- Window properties. If you are using Retina display, be aware that these
220- values refer to the virual size. The actual buffer size will be 2 x.
221-
222- .. code :: python
223-
224- WINDOW = {
225- " size" : (1280 , 768 ),
226- " vsync" : True ,
227- " resizable" : False ,
228- " fullscreen" : False ,
229- " title" : " demosys-py" ,
230- " cursor" : False ,
231- }
232-
233- MUSIC
234- ~~~~~
235-
236- If ``MUSIC `` is defined, demosys will attempt to play. (We have only
237- tried mp3 files!)
238-
239- .. code :: python
240-
241- PROJECT_DIR = os.path.dirname(os.path.abspath(__file__ ))
242- MUSIC = os.path.join(PROJECT_DIR , ' resources/music/tg2035.mp3' )
243-
244- TIMER
245- ~~~~~
246-
247- This is the timer class that controls time in your project.
248- This defaults to ``demosys.timers.Timer `` that is simply keeps
249- track of system time using ``glfw ``.
250-
251- ```demosys.timers.MusicTimer` `` requires ``MUSIC `` to be defined
252- and will use the current time in the mp3.
253-
254-
255- EFFECTS
256- ~~~~~~~
257-
258- Effect packages demosys will initialize and use (Same as apps in
259- Django). Currently all effects registered will run simultaneously as we
260- currently don't have a time line concept for scheduling when they should
261- run. (SOON!)
262-
263- .. code :: python
264-
265- EFFECTS = (
266- ' testproject.cube' ,
267- )
268-
269- SHADER\_\*
270- ~~~~~~~~~~
271-
272- ``DIRS `` contains absolute paths the ``FileSystemFinder `` will look for
273- shader while ``EffectDirectoriesFinder `` will look for shaders in all
274- registered effects in the order they were added.
275-
276- .. code :: python
277-
278- SHADER_DIRS = (
279- os.path.join(PROJECT_DIR , ' resources/shaders' ),
280- )
281-
282- SHADER_FINDERS = (
283- ' demosys.core.shaderfiles.finders.FileSystemFinder' ,
284- ' demosys.core.shaderfiles.finders.EffectDirectoriesFinder' ,
285- )
286-
287- TEXTURE\_\*
288- ~~~~~~~~~~~
289-
290- Same principle as shaders.
291-
292- .. code :: python
293-
294- # Hardcoded paths to shader dirs
295- TEXTURE_DIRS = (
296- os.path.join(PROJECT_DIR , ' resource/textures' ),
297- )
298-
299- # Finder classes
300- TEXTURE_FINDERS = (
301- ' demosys.core.texturefiles.finders.FileSystemFinder' ,
302- ' demosys.core.texturefiles.finders.EffectDirectoriesFinder'
303- )
304-
305- SCREENSHOT_PATH
306- ~~~~~~~~~~~~~~~
307-
308- Absolute path to the directory screenshots will be saved.
309- If not defined or the directory don't exist, the current working directory will be used.
310-
311- .. code :: python
312-
313- SCREENSHOT_PATH = os.path.join(PROJECT_DIR , ' screenshots' )
314-
31544Known Issues
31645------------
31746
@@ -335,33 +64,37 @@ Use version 3.2.1 or later.
33564 context creation + input
33665- `PIL/Pillow <https://github.com/python-pillow/Pillow >`__ for texture
33766 loading
338- - https://www.pygame.org using the mixer module for music
33967- https://github.com/adamlwgriffiths/Pyrr for math (uses numpy)
34068
341- Credits
342- -------
343-
344- - Music in testdemo _ by `binaryf <https://github.com/binaryf >`__
345- - Also thanks to `Attila
346- Toth <https://www.youtube.com/channel/UC4L3JyeL7TXQM1f3yD6iVQQ> `__
347- for an excellent tutorial on OpenGL in Python. We do know OpenGL, but
348- had no clue where to start in the Python world.
69+ Optional for audio:
70+ - https://www.pygame.org using the mixer module for music
34971
35072What inspired us to make this project?
35173--------------------------------------
35274
353- - We are old farts from the demoscene
354- - We love Python
355- - We work a lot with Django and love it
75+ - We are old farts from the demoscene
76+ - We love Python
77+ - We were wondering what would be done with OpenGL in Python
78+ - We work a lot with Django and love it
35679
35780Why not combine ideas from our own demosys written in C++ and Django
35881making a Python 3 version?
35982
83+ Credits
84+ -------
85+
86+ - Also thanks to `Attila
87+ Toth <https://www.youtube.com/channel/UC4L3JyeL7TXQM1f3yD6iVQQ> `__
88+ for an excellent tutorial on OpenGL in Python.
89+
90+
36091.. _testdemo : https://github.com/Contraz/demosys-py-test
36192.. |pypi | image :: https://img.shields.io/pypi/v/demosys-py.svg
36293 :target: https://pypi.python.org/pypi/demosys-py
36394.. |travis | image :: https://travis-ci.org/Contraz/demosys-py.svg?branch=master
36495 :target: https://travis-ci.org/Contraz/demosys-py
96+ .. |rtd | image :: https://readthedocs.org/projects/demosys-py/badge/?version=latest
97+ :target: http://demosys-py.readthedocs.io/en/latest/?badge=latest
36598.. |screenshot1 | image :: https://objects.zetta.io:8443/v1/AUTH_06e2dbea5e824620b20b470197323277/contraz.no-static/gfx/productions/SimLife3.png
36699.. |screenshot2 | image :: https://objects.zetta.io:8443/v1/AUTH_06e2dbea5e824620b20b470197323277/contraz.no-static/gfx/productions/SimLife2.png
367-
100+ .. _ readthedocs : http://demosys-py.readthedocs.io/
0 commit comments