# Inline Shader code will not run

**URL:** <https://discourse.processing.org/t/inline-shader-code-will-not-run/40627>\
**Category:** Coding Questions\
**Created:** [January 18, 2023, 2:43am UTC](https://discourse.processing.org/t/inline-shader-code-will-not-run/40627 "2023-01-18T02:43:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [January 18, 2023, 2:43am UTC](https://discourse.processing.org/t/inline-shader-code-will-not-run/40627/1 "2023-01-18T02:43:10Z")

</div>

The following Processing code using inline shaders will not run on a Mac due to this error:

```plaintext
ERROR: 0:6: 'attribute' : syntax error: syntax error

```

The same code using separate .glsl files in the sketch folder runs ok. The only difference is that the frag.glsl and vert.glsl files neither one have the _#version_ line of code. If I try putting the _#version_ line in the separate files I get the attribute error as shown above. In contradistinction, the inline shader code shown here will throw an error message if you leave the #version line out; it has to be there for inline code. The ‘attribute’ syntax causes no problem in a separate vert.glsl file, but throws an error with inline shader code for reasons I do not understand. Macs supposedly support #version 410 (I also tried 330 with same result).

```auto
PShape sh;
PShader shader;

void setup() {
  size(300, 300, P3D);
  strokeWeight(30.00);
  sh = createShape();
  sh.beginShape(POINTS);
  sh.vertex(120, 80, 0);
  sh.endShape(CLOSE);
  shader = new PShader(g.parent, vertSrc, fragSrc);
  println(g.parent);
}

void draw() {
  shader(shader); 
  shape(sh);
}

String[] vertSrc = {"""
#version 410
uniform mat4 projection;
uniform mat4 modelview;

attribute vec4 position;
attribute vec4 color;
attribute vec2 offset;

void main() {
  vec4 pos = modelview * position;
  vec4 clip = projection * pos;  
  gl_Position = clip + projection * vec4(offset, 0, 0);
} 
"""};

String[] fragSrc = {"""
#version 410
out vec4 outColor;
void main() {
  outColor = vec4(0.0, 0.0, 1.0, 1.0);
}
"""};

```

---

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [January 18, 2023, 3:43am UTC](https://discourse.processing.org/t/inline-shader-code-will-not-run/40627/2 "2023-01-18T03:43:36Z")

</div>

Change `attribute` to `in`:

`in vec4 position;`

and likewise, `varying` is replaced with `out`.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [January 18, 2023, 4:17am UTC](https://discourse.processing.org/t/inline-shader-code-will-not-run/40627/3 "2023-01-18T04:17:32Z")

</div>

Works like a charm; thanks.
