PK #ŠBLr¡VN VN python-cg-latest/index.html
python-cg is a Python wrapper for NVidia Cg Toolkit runtime. I’ve started it because I like Python, I like NVidia CG and I want to to do some computer game/3d graphicsprototyping and research. Also I still find C++ counterproductive as far as my needs are concerned and I don’t want to waste my time doing boring stuff. Programming in Python is fun.
I know about some projects that were meant to bring CG to Python but as far as I know they’re history now.
Project is hostead at GitHub: https://github.com/jstasiak/python-cg.
The project is in very early development stage. Overview of what’s supported right now:
What doesn’t work at the moment and there’s no plan to implement it:
This project requires:
Python packages required to build and install python-cg:
To build documentation/run tests you also need:
Pregenerated documentation can be found at https://python-cg.readthedocs.org/en/latest/.
You can also build documentation all by yourself by calling:
sphinx-build -b html docs docs/build/html
Generated HTML files are placed in docs/build/html/ directory.
First you need to create an instance of CG class and use it to create new Context:
from cg import CG
cg = CG()
context = cg.create_context()
We want to use an effect to render some stuff so we’re gonna create Effect from file:
effect = context.create_effect_from_file('effect.cgfx')
Note
This assumes that you have a file named effect.cgfx and that it contains a valid CG effect.
We now have access to Effect’s techniques and parameters:
for technique in effect.techniques:
# ...
for parameter in effect.parameters:
# ...
For the sake of simplicity let’s say we have a parameterless effect with only one Technique:
technique = effect.techniques[0]
Now we can access technique’s passes. Each Pass has methods begin() and end() and the actual drawing has to take place between a call to begin and end:
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
for pass_ in technique.passes:
pass_.begin()
gl.glBegin(gl.GL_TRIANGLES)
gl.glVertex3f(-0.5, -0.5, 0)
gl.glVertex3f(0.5, -0.5, 0)
gl.glVertex3f(0, 0.5, 0)
gl.glEnd()
pass_.end()
# swap buffers
You can find complete, runnable example application in example directory. Please note that it requires (in addition to python-cg requirements):
Development version of SFML 2
Python packages listed in example/requirements.txt:
pip install -r example/requirements.txt
Then to run the example:
python setup.py build_ext --inplace
PYTHONPATH=. python example/main.py
Bases: cg.utils.Disposable
Wraps CG Effect.
Gets effect parameters as a cg.parameter.ParameterCollection.
Gets techniques defined for an effect as a tuple of cg.effect.technique.EffectTechnique.
Bases: object
Contains state for rendering with an effect.
Begins the rendering pass.
See also
Ends the rendering pass.
See also
Bases: cg.utils.ReprMixin
Effect technique.
Gets the name of the technique (string)
Gets technique passes as a tuple of cg.effect.pass_.Pass
Gets whether the technique is valid on current hardware or not (bool)
Bases: cg.utils.Disposable
Gateway to using python-cg.
Note
This is the only class that should (or need to) be manually instantiated
by user code.
Note
There should be one instance of this class per process. Having multiple instances, although possible, can result in some unexpected behaviour.
Creates CG context.
Return type: | cg.context.Context |
---|
Bases: cg.utils.Disposable
Wraps Cg context.
Creates effect from source.
Parameters: | source (string) – effect source |
---|---|
Return type: | cg.effect.Effect |
Loads effect source from file and creates effect using it.
Parameters: | filename (string) – file containing effect source. |
---|---|
Return type: | cg.effect.Effect |
Bases: cg.parameter.Parameter
Represents numeric parameter (float, array of ints, matrix of doubles etc.).
Gets parameter column count
Gets parameter row count
Sets the parameter value. Value can be one of the following:
Note
Setting parameter value is a slow operation and should be performed as rarely as possible.
Note
Matrices will be filled with data in row-major order.
Bases: cg.utils.ReprMixin
Effect or program parameter base class.
Gets base type of the parameter (string)
Gets name of the parameter (string)
Gets parameter semantic (string)
Gets type of the parameter (string)
Bases: tuple
Collection of cg.parameter.Parameter. Provides tuple interface (iteration, indexing etc.) and some parameter-specific extensions.
Bases: cg.parameter.Parameter
Represents sampler* parameter.
Bases: abc.WithABCMeta
Exposes method to release resources held by the class.
Please activate JavaScript to enable the search functionality.
From here you can search these documents. Enter your search words into the box below and click "search". Note that the search function will automatically search for all of the words. Pages containing fewer words won't appear in the result list.