It's possible for sure: http://www.hardcorepawn.com/Shiny/
However you do have to use GLSL shaders to achieve it I think. Unfortunately the above was made before the beginGL() functions were added to make getting to pure GL easy so the full source wouldn't be all that useful.
I've not tried to use shaders in a while so how to best integrate them may have changed, but the below should give you a good starting point:
GLSL class:
Code:class GLSL
{
int programObject;
GL gl;
boolean vertexShaderEnabled;
boolean vertexShaderSupported;
int vs;
int fs;
GLSL()
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
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)
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
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)
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
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)
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
return(gl.glGetAttribLocationARB(programObject,name));
}
int getUniformLocation(String name)
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
return(gl.glGetUniformLocationARB(programObject,name));
}
void useShaders()
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
gl.glLinkProgramARB(programObject);
gl.glValidateProgramARB(programObject);
checkLogInfo(gl, programObject);
}
void startShader()
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
gl.glUseProgramObjectARB(programObject);
}
void endShader()
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
gl.glUseProgramObjectARB(0);
}
void checkLogInfo(GL gl, int obj)
{
gl=((PGraphicsOpenGL)g).beginGL();
((PGraphicsOpenGL)g).endGL();
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));
}
}
Main code:
Code:
GLSL glsl;
void setup()
{
// ... normal setup stuff ...
glsl=new GLSL();
glsl.loadVertexShader("myShader.vert");
glsl.loadFragmentShader("myShader.frag");
glsl.useShaders();
}
void draw()
{
//might need a ((PGraphicsOpenGL)g).beginGL(); here
glsl.startShader();
//draw stuff
glsl.endShader();
}