Reputation: 305
I recently started learning opengl and still don't know very much about it. I was following a tutorial and wrote these two shaders:
Vertex Shader:
#version 400
in vec4 s_vPosition;
in vec4 s_vColor;
out vec4 color;
void main() {
color = s_vColor;
gl_Position = s_vPosition;
}
Fragment Shader:
#version 400
in vec4 color;
out vec4 fColor;
void main() {
fColor = color;
}
They compile and work just fine on the desktop with OpenGL 3, but don't compile with OpenGL ES 2 on Android. I tried checking the shader output log, but it returned a blank string. Again, I am very new to this and my mistake is probably very simple, but any help would be highly appreciated.
Upvotes: 0
Views: 198
Reputation: 24417
In OpenGLES2 you don't use the in
and out
variable prefixes like in 3.0. Instead you use the following keywords:
An attribute
corresponds to an in
in a vertex shader.
A varying
corresponds to an out
in a vertex shader and an in
in a fragment shader. So, change your vertex shader to this:
attribute vec4 s_vPosition;
attribute vec4 s_vColor;
varying vec4 color;
void main() {
color = s_vColor;
gl_Position = s_vPosition;
}
and your fragment shader to this:
varying vec4 color;
void main() {
gl_FragColor = color;
}
gl_FragColor
is a specially defined variable like gl_Position
used for outputting the color from a fragment shader.
Upvotes: 4