GLSL compile error from basic SimpleApplication

Hi, I’ve created a very simple subclass of SimpleApplication but I’m getting a very strange error with no idea what’s causing it. What’s more, this used to work just fine, but it seems something has changed on my system that is breaking it. A new workspace runs this code just fine on a coworker’s computer.

I get a ‘bad compile’ message which prints out a concatenation of the files Common/ShaderLib/Skinning.glsllib and Common/MatDefs/Misc/Unshaded.vert. (As a result of preprocessor copy-pasting).

The error says I’m missing a ‘#version’ at the top of the file. Of course, I haven’t changed the file. My understanding is that the GLSL compiler should interpret files with no specified version as being version 110.

The second complaint is about a syntax error on ‘attribute,’ line 76. I don’t see anything wrong here.

I’ve tried specifying the version of OpenGL to use via AppSettings, but that seems to have no effect.

When I run the code through the debugger I see that there is a string ‘language’ set to “GLSL100” but also an int ‘version’ set to 150. This is in LwjglRenderer.

Any help on this would be much appreciated. I’m pretty well stumped.

[java]
Jun 03, 2014 9:03:29 AM com.jme3.renderer.lwjgl.LwjglRenderer updateShaderSourceData
WARNING: Bad compile of:
1 #define HAS_COLOR 1
2 #ifdef NUM_BONES
3
4 #if NUM_BONES < 1 || NUM_BONES > 255
5 #error NUM_BONES must be between 1 and 255.
6 #endif
7
8 #define NUM_WEIGHTS_PER_VERT 4
9
10 attribute vec4 inHWBoneWeight;
11 attribute vec4 inHWBoneIndex;
12 uniform mat4 m_BoneMatrices[NUM_BONES];
13
14 void Skinning_Compute(inout vec4 position){
15 if (inHWBoneWeight.x != 0.0) {
16 #if NUM_WEIGHTS_PER_VERT == 1
17 position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
18 #else
19 mat4 mat = mat4(0.0);
20 mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
21 mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
22 mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
23 mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
24 position = mat * position;
25 #endif
26 }
27 }
28
29 void Skinning_Compute(inout vec4 position, inout vec3 normal){
30 if (inHWBoneWeight.x != 0.0) {
31 #if NUM_WEIGHTS_PER_VERT == 1
32 position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
33 normal = (mat3(m_BoneMatrices[int(inHWBoneIndex.x)][0].xyz,
34 m_BoneMatrices[int(inHWBoneIndex.x)][1].xyz,
35 m_BoneMatrices[int(inHWBoneIndex.x)][2].xyz) * normal);
36 #else
37 mat4 mat = mat4(0.0);
38 mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
39 mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
40 mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
41 mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
42 position = mat * position;
43
44 mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
45 normal = rotMat * normal;
46 #endif
47 }
48 }
49
50 void Skinning_Compute(inout vec4 position, inout vec3 tangent, inout vec3 normal){
51 if (inHWBoneWeight.x != 0.0) {
52 #if NUM_WEIGHTS_PER_VERT == 1
53 position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
54 tangent = m_BoneMatrices[int(inHWBoneIndex.x)] * tangent;
55 normal = (mat3(m_BoneMatrices[int(inHWBoneIndex.x)][0].xyz,
56 m_BoneMatrices[int(inHWBoneIndex.x)][1].xyz,
57 m_BoneMatrices[int(inHWBoneIndex.x)][2].xyz) * normal);
58 #else
59 mat4 mat = mat4(0.0);
60 mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
61 mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
62 mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
63 mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
64 position = mat * position;
65
66 mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
67 tangent = rotMat * tangent;
68 normal = rotMat * normal;
69 #endif
70 }
71 }
72
73 #endif
74
75 uniform mat4 g_WorldViewProjectionMatrix;
76 attribute vec3 inPosition;
77
78 #if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
79 #define NEED_TEXCOORD1
80 #endif
81
82 attribute vec2 inTexCoord;
83 attribute vec2 inTexCoord2;
84 attribute vec4 inColor;
85
86 varying vec2 texCoord1;
87 varying vec2 texCoord2;
88
89 varying vec4 vertColor;
90
91 void main(){
92 #ifdef NEED_TEXCOORD1
93 texCoord1 = inTexCoord;
94 #endif
95
96 #ifdef SEPARATE_TEXCOORD
97 texCoord2 = inTexCoord2;
98 #endif
99
100 #ifdef HAS_VERTEXCOLOR
101 vertColor = inColor;
102 #endif
103
104 vec4 modelSpacePos = vec4(inPosition, 1.0);
105 #ifdef NUM_BONES
106 Skinning_Compute(modelSpacePos);
107 #endif
108 gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
109 }

Jun 03, 2014 9:03:29 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Misc/Unshaded.vert, defines, type=Vertex, language=GLSL100] error:ERROR: 0:1: ‘’ : #version required and missing.
ERROR: 0:76: ‘attribute’ : syntax error syntax error

The rest of the post got dropped. Here’s my code:

[java]
import com.jme3.app.SimpleApplication;

public class VerySimpleApplication
extends SimpleApplication
{

@Override
public void simpleInitApp()
{
    // TODO Auto-generated method stub

}

public static void main(String[] args)
{
    VerySimpleApplication app = new VerySimpleApplication();

    app.start();
}

}
[/java]

Stacktrace:

[java]
at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderSourceData(LwjglRenderer.java:1018)
at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderData(LwjglRenderer.java:1041)
at com.jme3.renderer.lwjgl.LwjglRenderer.setShader(LwjglRenderer.java:1107)
at com.jme3.material.Material.render(Material.java:1116)
at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:523)
at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:322)
at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:371)
at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:788)
at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:719)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:983)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1035)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
[/java]

You say it worked before? Or it never worked on this computer?

JME adds the version at the beginning of the shader and for some reason it seems to miss in the logged shader code.
If the #version is not specified, it use the higher version supported, and it seems it’s 1.5 on your computer. In glsl 1.5 the “attribute” keyword has been replaced by “in”. that’s why you get the error.

Are you running with the git master? I know something has changed recently with the version management.

@Momoko_Fan, any idea?

@nehon said: Are you running with the git master?

Note that this question doesn’t imply that you should use the git master.

@normen said: Note that this question doesn't imply that you should use the git master.
No that's not what I meant, it's just that something changed recently, that would explain the sudden error. My question should have been : What version of JME do you use? ;)

It looks like I have stable version 3.0.5 of JMonkey installed, but I’ve been using jars from November 2013 (my project is in Eclipse - I’m not using the JME3 SDK). It could be that installing the newer version messed something up, but I’ve tried running with the latest jars from April of this year and I still get the same error.

Probably you have Core OpenGL 3.x set as your Renderer in the AppSettings (that setting is loaded from disk / registry). You will need to change it to the default OpenGL 2:

[java]VerySimpleApplication app = new VerySimpleApplication();
AppSettings settings = new AppSettings(true);
settings.setRenderer(AppSettings.LWJGL_OPENGL2);
app.setSettings(settings);
app.start();[/java]

Yes, that it is the problem. I was setting the settings in the wrong way. Thanks!