Why shader doesn't get compiled?

198 views
Skip to first unread message

Alexander DIY

unread,
Dec 4, 2014, 5:58:20 PM12/4/14
to kivy-...@googlegroups.com
Hello,

I ended up creating very basic example after fighting with shaders in my current project. They work some times and some times not. In this example I try to compile a simple shader, but obviously compilation fails. App logs don't contain any useful information except for that compilation failed. Perhaps I'm missing something. Could somebody point me on what I'm doing wrong?

class KanvasApp(App):
    def build(self):
        simple = Shader(source='simple.glsl')
        if not simple.success:
            raise Exception("Simple shader didn't compile.")

        root = BoxLayout(orientation='vertical')
        return root

if __name__ == "__main__":
    KanvasApp().run()

simple.glsl contents:
---VERTEX SHADER--- // vertex shader starts here
#ifdef GL_ES
    precision highp float;
#endif

/* Outputs to the fragment shader */
varying vec4 frag_color;
varying vec2 tex_coord0;

/* vertex attributes */
attribute vec2     vPosition;
attribute vec2     vTexCoords0;

/* uniform variables */
uniform mat4       modelview_mat;
uniform mat4       projection_mat;
uniform vec4       color;
uniform float      opacity;

void main() {
  gl_Position = projection_mat * modelview_mat * vec4(vPosition.xyz, 1.0);
}

---FRAGMENT SHADER--- // fragment shader starts here
#ifdef GL_ES
    precision highp float;
#endif

/* Outputs from the vertex shader */
varying vec4 frag_color;
varying vec2 tex_coord0;

/* uniform texture samplers */
uniform sampler2D texture0;

void main(void)
{
   gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

App start logs:
[INFO              ] [Logger      ] Record log in /home/alex/.kivy/logs/kivy_14-12-04_59.txt
[INFO              ] Kivy v1.9.0-dev
[INFO              ] [Python      ] v3.4.2 (default, Oct  8 2014, 13:44:52)
[GCC 4.9.1 20140903 (prerelease)]
[INFO              ] [Factory     ] 172 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif (img_sdl2, img_ffpyplayer ignored)
[INFO              ] [Shader      ] Read <simple.glsl>
[ERROR             ] [Shader      ] <vertex> failed to compile (gl:0)
[ERROR             ] [Shader      ] <fragment> failed to compile (gl:0)
 
Traceback (most recent call last):
   
File "/home/alex/{cut off}/main.py", line 16, in <module>
     
KanvasApp().run()
   
File "/usr/lib/python3.4/site-packages/kivy/app.py", line 799, in run
     root
= self.build()
   
File "/home/alex/{cut off}/main.py", line 10, in build
     
raise Exception("Simple shader didn't compile.")
 
Exception: Simple shader didn't compile.

Process finished with exit code 1

This very minimalistic project is attached.

Best regards,
Alex.
kivyshader.zip

Alexander Taylor

unread,
Dec 4, 2014, 7:10:37 PM12/4/14
to kivy-...@googlegroups.com
I'm not sure if this is important, but could you try putting 'import eventloop; eventloop.ensure_window()' before anything else in the build method?

Kovak

unread,
Dec 4, 2014, 8:58:56 PM12/4/14
to kivy-...@googlegroups.com
attribute vec2     vPosition;

 vec4(vPosition.xyz, 1.0);


it does not compile because there is only 2 components.

Kovak

unread,
Dec 4, 2014, 9:01:07 PM12/4/14
to kivy-...@googlegroups.com
You also do not write to your varyings.

Alexander DIY

unread,
Dec 5, 2014, 9:06:17 AM12/5/14
to kivy-...@googlegroups.com
Thanks for answers!
I found the solution. Compilation works if I do import
from kivy.core.window import Window
even if I never use Window explicilty.
After that I see shader compiler errors that you've mentioned, but it is kinda another issue that I can fix now.
So I beleave something very important happens in that module so it must be included. Looks like a bug to me or at least it should be mentioned in docs.
Reply all
Reply to author
Forward
0 new messages