LwShader

LwShader — OpenGL shader wrapper

Functions

Types and Values

struct LwShader
struct LwShaderClass

Object Hierarchy

    GObject
    ╰── LwShader

Description

LwShader makes it easy to load and create OpenGL shaders. You can avoid using this structure if you use the lw_program_create_and_attach_shader() function.

LwShader is not finished yet. It is possible that parts of this type will be changed in a future version of LiveWallpaper.

Example 8. Using LwShader

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
GError *error = NULL;
LwProgram *prog = g_object_new(LW_TYPE_PROGRAM, NULL);

LwShader *shader = lw_shader_new_from_uri("/path/to/shader.glsl", GL_FRAGMENT_SHADER, &error);
if(error != NULL)
{
    g_warning("Could not load fragment shader: %s", error->message);
    g_error_free(error);
    return;
}
else
{
    lw_shader_compile(shader);
    lw_program_attach_shader(prog, shader);
}
g_object_unref(shader);

lw_program_link(prog);

...

Functions

lw_shader_new_from_uri ()

LwShader *
lw_shader_new_from_uri (const gchar *uri,
                        guint type);

Creates a new shader and stores the content of the file as source code in in the shader. This function will return NULL if it cannot get the source code from the specified file. The uri has to begin with the protocol, by instance file:// or resource://

Parameters

uri

The uri of the file containing the shader's source code

 

type

GL_VERTEX_SHADER or GL_FRAGMENT_SHADER

 

Returns

A new LwShader or NULL if an error occured. You should use g_object_unref() to free the LwShader.

Since: 0.5


lw_shader_new_from_string ()

LwShader *
lw_shader_new_from_string (const gchar *source,
                           guint type);

Creates a new shader and stores the source code in the shader.

Parameters

source

The source code of the shader

 

type

GL_VERTEX_SHADER or GL_FRAGMENT_SHADER

 

Returns

A new LwShader. You should use g_object_unref() to free the LwShader.

Since: 0.4


lw_shader_compile ()

gboolean
lw_shader_compile (LwShader *self);

Compiles the source code of the shader. This function prints a warning if the compilation of the shader fails.

Parameters

self

A LwShader

 

Returns

TRUE on success, FALSE if the compilation failed

Since: 0.4


lw_shader_get_name ()

guint
lw_shader_get_name (LwShader *self);

Parameters

self

A LwShader

 

Returns

The shader name returned by glCreateShader

Since: 0.4


lw_shader_get_shader_type ()

guint
lw_shader_get_shader_type (LwShader *self);

Parameters

self

A LwShader

 

Returns

The type of the shader, either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER

Since: 0.4

Types and Values

struct LwShader

struct LwShader;

A structure for easier OpenGL shader handling.

Since: 0.4


struct LwShaderClass

struct LwShaderClass {
};