We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Bumpmaps in processing
Page Index Toggle Pages: 1
Bumpmaps in processing? (Read 1076 times)
Bumpmaps in processing?
Jan 9th, 2008, 12:15pm
 
Is anyone familiar with simple bumpmaps in jogl? Is it possible (in a fairly simple way!) to get them working in processing-opengl?

Any tips on reads on this subject?
Re: Bumpmaps in processing?
Reply #1 - Jan 9th, 2008, 12:30pm
 
do you mean 2d bumpmaps? you might find some info on the web. i could post some sample i made sometime ago in processing.
Re: Bumpmaps in processing?
Reply #2 - Jan 9th, 2008, 12:36pm
 
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();
}
Page Index Toggle Pages: 1