1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
.. py:currentmodule:: moderngl
Program
=======
ModernGL is different from standard plotting libraries.
You can define your own shader program to render stuff.
This could complicate things, but also provides freedom on how you render
your data.
Previously, we looked at creating a :doc:`vertex shader-only program <../low_start/shader_transform>` that could only read data from the input buffer and write the converted data to the output buffer. Now let's add a fragment shader to our program; it will allow us to create an algorithm for writing pixels into a texture, that is, perform the :doc:`main function <../low_start/shader_basics>` of the shader.
Here is a sample program that passes the input vertex coordinates as is to
screen coordinates.
Screen coordinates are in the [-1, 1], [-1, 1] range for x and y axes.
The (-1, -1) point is the lower left corner of the screen.
.. figure:: screen_coordinates.png
:alt: Screen Coordinates
:align: center
:figclass: align-center
The screen coordinates
The program will also process a color information.
.. rubric:: Entire source
.. literalinclude:: first.1.py
:emphasize-lines: 5-
:linenos:
.. rubric:: Vertex Shader
.. literalinclude:: first.1.py
:language: glsl
:dedent: 8
:lines: 7-17
.. rubric:: Fragment Shader
.. literalinclude:: first.1.py
:language: glsl
:dedent: 8
:lines: 20-28
Proceed to the :doc:`next step <buffer>`.
|