Commit 3b4bf963 authored by Emmanuele Bassi's avatar Emmanuele Bassi

demo: Move the GLSL shaders to resources

It's easier to use them or modify them as separate files, instead of
inlined inside the C source.

https://bugzilla.gnome.org/show_bug.cgi?id=741946
parent 2d35053d
......@@ -136,6 +136,8 @@ RESOURCES = \
brick2.png \
background.jpg \
floppybuddy.gif \
glarea-fragment.glsl \
glarea-vertex.glsl \
gnome-applets.png \
gnome-calendar.png \
gnome-foot.png \
......
......@@ -140,4 +140,8 @@
<gresource prefix="/popover">
<file>popover.ui</file>
</gresource>
<gresource prefix="/shaders">
<file>glarea-fragment.glsl</file>
<file>glarea-vertex.glsl</file>
</gresource>
</gresources>
#version 330
out vec4 outputColor;
void main() {
float lerpVal = gl_FragCoord.y / 500.0f;
outputColor = mix(vec4(1.0f, 0.85f, 0.35f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpVal);
}
#version 330
layout(location = 0) in vec4 position;
uniform mat4 mvp;
void main() {
gl_Position = mvp * position;
}
......@@ -91,26 +91,6 @@ create_shader (int type,
return shader;
}
/* The code for the vertex shader we are going to use */
static const char *vertex_shader_code =
"#version 330\n" \
"\n" \
"layout(location = 0) in vec4 position;\n" \
"uniform mat4 mvp;\n"
"void main() {\n" \
" gl_Position = mvp * position;\n" \
"}";
/* The code for the fragment shader we are going to use */
static const char *fragment_shader_code =
"#version 330\n" \
"\n" \
"out vec4 outputColor;\n" \
"void main() {\n" \
" float lerpVal = gl_FragCoord.y / 400.0f;\n" \
" outputColor = mix(vec4(1.0f, 0.85f, 0.35f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpVal);\n" \
"}";
/* Initialize the shaders and link them into a program */
static void
init_shaders (GLuint *program_out,
......@@ -120,15 +100,22 @@ init_shaders (GLuint *program_out,
GLuint program = 0;
GLuint mvp = 0;
int status;
GBytes *source;
source = g_resources_lookup_data ("/shaders/glarea-vertex.glsl", 0, NULL);
vertex = create_shader (GL_VERTEX_SHADER, g_bytes_get_data (source, NULL));
g_bytes_unref (source);
vertex = create_shader (GL_VERTEX_SHADER, vertex_shader_code);
if (vertex == 0)
{
*program_out = 0;
return;
}
fragment = create_shader (GL_FRAGMENT_SHADER, fragment_shader_code);
source = g_resources_lookup_data ("/shaders/glarea-fragment.glsl", 0, NULL);
fragment = create_shader (GL_FRAGMENT_SHADER, g_bytes_get_data (source, NULL));
g_bytes_unref (source);
if (fragment == 0)
{
glDeleteShader (vertex);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment