We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I started with OpenGL 4.0 Shading Language Cookbook cause it's a well recommended book. Only I can't even get the first examples to work... oO. And for the purpose of learning I really want to do it in processing. I tried to adapt it to processing.
Those are the errors I get:
java.lang.RuntimeException: java.lang.RuntimeException: Cannot compile vertex shader:
ERROR: 0:1: Invalid qualifiers 'in' in global variable context
ERROR: 0:2: Invalid qualifiers 'in' in global variable context
ERROR: 0:4: Invalid qualifiers 'out' in global variable context
ERROR: 0:7: Use of undeclared identifier 'Color'
ERROR: 0:7: Use of undeclared identifier 'VertexColor'
ERROR: 0:8: Use of undeclared identifier 'VertexPosition'
BasicFrag.glsl
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_COLOR_SHADER
in vec3 Color;
out vec4 FragColor;
void main() {
FragColor = vec4(Color, 1.0);
}
basicVert.glsl
in vec3 VertexPosition;
in vec3 VertexColor;
out vec3 Color;
void main() {
Color = VertexColor;
gl_Position = vec4( VertexPosition, 1.0);
}
About the processing code, I have no clue at all but I would even be happy if the sketch can run.
PShader basic;
void setup() {
size(640, 360, P3D);
noStroke();
basic = loadShader("basicFrag.glsl", "basicVert.glsl");
}
void draw() {
shader(basic);
background(0);
beginShape(QUADS);
fill(0, 1, 1); vertex(-1, 1, 1);
fill(1, 1, 1); vertex( 1, 1, 1);
fill(1, 0, 1); vertex( 1, -1, 1);
fill(0, 0, 1); vertex(-1, -1, 1);
endShape();
}
I hope someone can help.
Answers
I thought Processing 2 series used OpenGL 2 or something.
I even heard that Processing 1 series used OpenGL 1!
See: http://www.processing.org/tutorials/pshader/
=> Code listing 4.2
I did that tutorial but it's not really helpfull.
OpenGL 2.0 is only 10 years old :)
@GoToLoop: By default Processing 2.0+ follows the OpenGL ES 2.0 specifications to ensure it will run on both desktop and mobile platforms. However you can get the underlying JOGL objects and access all the GL functions for profiles 3.0+, for example to use geometry and tessellation shaders.
@clankill3r: Perhaps you are dismissing this tutorial too quickly. If you want to use shaders in Processing, this is pretty much the basic knowledge you should have. So I believe there really is some valuable information in there. Having said that, I think more basic shader example would be helpful and it is in fact already an issue on GitHub, here. Also note that, compared with only a year ago, there seem to be more Processing shader examples around (especially on GitHub).
Now the specifics, there are a few problems with your code:
Below is the fixed code...
Processing Code
basicVert.glsl
basicFrag.glsl
How I wish Processing's own pre-processor had
#define
&#ifdef
... :-<This way, we could write 1 source code which would work in multi-modes! $-)