GLSL is certainly possible, in fact I've written a class to handle everything for you.
It should be noted however, that if you use processing's OPENGL then some features maty behave oddly, as processing does some transforms in software, before they get handed over to OpenGL.
There's 2 two workaround to this, do: camera(0,0,0,0,0,-1,0,1,0);
And after that only do pur OpenGL work, e.g. no processing beginShape()/vertex() etc, only gl.glBeginShape()/g.glVertex3f() etc.
Or you could try the proGL library, this GLSL code should work with it, but its untested.
Code:class GLSL
{
int programObject;
GL gl;
boolean vertexShaderEnabled;
boolean vertexShaderSupported;
int vs;
int fs;
GLSL()
{
gl=((PGraphicsGL)g).gl;
String extensions = gl.glGetString(GL.GL_EXTENSIONS);
vertexShaderSupported = extensions.indexOf("GL_ARB_vertex_shader") != -1;
vertexShaderEnabled = true;
programObject = gl.glCreateProgramObjectARB();
vs=-1;
fs=-1;
}
void loadVertexShader(String file)
{
String shaderSource=join(loadStrings(file),"\n");
vs = gl.glCreateShaderObjectARB(GL.GL_VERTEX_SHADER_ARB);
gl.glShaderSourceARB(vs, 1, new String[]{shaderSource},(int[]) null, 0);
gl.glCompileShaderARB(vs);
checkLogInfo(gl, vs);
gl.glAttachObjectARB(programObject, vs);
}
void loadFragmentShader(String file)
{
String shaderSource=join(loadStrings(file),"\n");
fs = gl.glCreateShaderObjectARB(GL.GL_FRAGMENT_SHADER_ARB);
gl.glShaderSourceARB(fs, 1, new String[]{shaderSource},(int[]) null, 0);
gl.glCompileShaderARB(fs);
checkLogInfo(gl, fs);
gl.glAttachObjectARB(programObject, fs);
}
int getAttribLocation(String name)
{
return(gl.glGetAttribLocationARB(programObject,name));
}
int getUniformLocation(String name)
{
return(gl.glGetUniformLocationARB(programObject,name));
}
void useShaders()
{
gl.glLinkProgramARB(programObject);
gl.glValidateProgramARB(programObject);
checkLogInfo(gl, programObject);
}
void startShader()
{
gl.glUseProgramObjectARB(programObject);
}
void endShader()
{
gl.glUseProgramObjectARB(0);
}
void checkLogInfo(GL gl, int obj)
{
IntBuffer iVal = BufferUtil.newIntBuffer(1);
gl.glGetObjectParameterivARB(obj, GL.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
int length = iVal.get();
if (length <= 1)
{
return;
}
ByteBuffer infoLog = BufferUtil.newByteBuffer(length);
iVal.flip();
gl.glGetInfoLogARB(obj, length, iVal, infoLog);
byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
println("GLSL Validation >> " + new String(infoBytes));
}
}
Usage:
Code:GLSL glsl;
void setup()
{
// normal stuff, size, gl=((PGraphicsGL)g).gl etc..
glsl=new GLSL();
glsl.loadVertexShader("MyShader.vert");
glsl.loadFragmentShader("MyShader.frag");
glsl.useShaders();
}
void draw()
{
//stuff unrelated to drawing...
//draw initial stuff that doens't need the shader.
glsl.startShader();
//draw things that you want the shader applied to
glsl.endShader();
// draw things that you don't want the shader applied to.
}
If you have a really complex scene, and want multiple shaders, you can just create more than one GLSL object, and startShader/endShader as and when needed.