Top | ![]() |
![]() |
![]() |
![]() |
LwProgram is an easy way to use GLSL shaders in a LiveWallpaper plugin.
LwProgram is not finished yet. It is possible that parts of this type will be changed in a future version of LiveWallpaper.
Example 9. Using LwProgram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
GError *error = NULL; LwProgram *prog = g_object_new(LW_TYPE_PROGRAM, NULL); lw_program_create_and_attach_shader(prog, "/path/to/shader.glsl", GL_VERTEX_SHADER, &error); if(error != NULL) { g_warning("Could not load vertex shader: %s", error->message); g_error_free(error); return; } lw_program_link(prog); ... lw_prog_enable(prog); // The program is enabled for all following drawing operations ... lw_prog_disable(prog); |
The noise plugin makes use of the LwProgram object. Take a look at the source code of that plugin to see a full working example for LwProgram.
void lw_program_attach_shader (LwProgram *self
,LwShader *shader
);
Attaches the shader to the program. This function uses glAttachShader to attach the shader. The LwShader can be freed after attaching it to a LwProgram.
Since: 0.4
gboolean lw_program_create_and_attach_shader (LwProgram *self
,const gchar *path
,guint type
);
This function creates, compiles and attaches a shader to the program. It is easier to use this function instead of creating, compiling and attaching the shader by yourself.
self |
||
path |
The file containing the shader's source code |
|
type |
GL_VERTEX_SHADER or GL_FRAGMENT_SHADER |
Since: 0.4
gboolean lw_program_create_and_attach_shader_from_resource (LwProgram *self
,const gchar *path
,guint type
);
This function creates, compiles and attaches a shader to the program. It is easier to use this function instead of creating, compiling and attaching the shader by yourself.
self |
||
path |
The file containing the shader's source code |
|
type |
GL_VERTEX_SHADER or GL_FRAGMENT_SHADER |
Since: 0.5
gint lw_program_get_attrib_location (LwProgram *self
,const gchar *name
);
Calls glGetAttribLocation to get the location of an attribute variable.
Since: 0.4
gint lw_program_get_uniform_location (LwProgram *self
,const gchar *name
);
Calls glGetUniformLocation to get the location of an uniform variable.
Since: 0.4
gboolean
lw_program_link (LwProgram *self
);
Links the program using glLinkProgram.
If an error occurs, this function returns FALSE
and prints a warning.
Since: 0.4
void lw_program_set_attribute (LwProgram *self
,const gchar *name
,LwGLSLType type
,LwBuffer *buffer
);
Binds buffer
to the attribute variable name
. Internally this function uses
to define the vertex attribute array and
glEnableVertexAttribArrayto enable it.
This function assumes that the data stored in the buffer
is tightly packed
(stride is 0) and there is no offset for the first component (pointer is 0, see parameters
of glVertexAttribPointer).
self |
||
name |
The name of an attribute variable |
|
type |
The LwGLSLType which represents the attribute's type |
|
buffer |
A LwBuffer |
Since: 0.5
void lw_program_set_matrix (LwProgram *self
,const gchar *name
,LwMatrix *matrix
);
Specifies the value of the matrix uniform variable name
.
Since: 0.5
void lw_program_set_texture (LwProgram *self
,const gchar *name
,LwTexture *texture
);
Binds the uniform variable name
to texture
. This function automatically binds
the texture to the next free texture unit and so it is able to handle multiple
textures for one LwProgram.
This functions calls lw_texture_bind_to()
, so you just have to call lw_texture_unbind()
or lw_texture_disable()
if necessary. If you do not unbind the texture after every paint,
make sure to unbind it in lw_wallpaper_restore_viewport()
.
Since: 0.5
Represents the GLSL type float |
||
Represents the GLSL type vec2 |
||
Represents the GLSL type vec3 |
||
Represents the GLSL type vec4 |
||
Represents the GLSL type int |
||
Represents the GLSL type ivec2 |
||
Represents the GLSL type ivec3 |
||
Represents the GLSL type ivec4 |
||
Represents the GLSL type bool |
||
Represents the GLSL type bvec2 |
||
Represents the GLSL type bvec3 |
||
Represents the GLSL type bvec4 |
Since: 0.5