So I decided to try writing a simple OpenGL app using Java, just to see how it compared to my other efforts, and I'm running into an issue where my shaders refuse to compile. They really couldn't get much simpler, here's my vertex shader to demonstrate what I mean:
//Minimal vertex shader
#version 330
in vec3 in_Position;
in vec3 in_Color;
out vec3 var_Color;
void main(void)
{
gl_Position = vec4(in_Position, 1.0);
var_Color = in_Color;
}
The fragment shader is just as simple, so I won't bother posting it unless someone asks for it. When I check the logs, I get back the following error (for both shaders):
(0) : error C0000: syntax error, unexpected $end at token "<EOF>"
I'm not sure this is relevant... but I'm developing on Linux (Ubuntu 11.04) using Java. The only libraries I'm using are JOGL (for the openGL bindings) and the standard Java library (if that even counts...) My graphics card is a Nvidia GeForce 9600M GS, and I checked the extensions and it has full support for OpenGL 3.3.
Help me Stack Overflow, you're my only hope.
EDIT:
As requested, here is the function that is responsible for loading and compiling the shader source. Also, when it comes to GLSL I'm a super n00b, so I really don't know what to look for as far as making sure things are formatted properly for OpenGL. A link to a recent (i.e. dealing with OpenGL 3.x) tutorial on the subject would be appreciated.
private int CreateCompiledShader(File source, int shader, GL3 gl){
int shaderloc = gl.glCreateShader(shader);
BufferedReader input = null;
ArrayList<String> lines = new ArrayList<String>();
ArrayList<Integer> lengths = new ArrayList<Integer>();
try{
input = new BufferedReader(new FileReader(source));
String buffer;
while(input.ready()){
buffer = input.readLine();
lines.add(buffer);
lengths.add(buffer.length());
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(input != null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
int[] iLengths = new int[lengths.size()];
for(int i = 0; i < lengths.size(); i++){
iLengths[i] = lengths.get(i).intValue();
}
gl.glShaderSource(shaderloc, lines.size(), lines.toArray(new String[0]), iLengths, 0);
gl.glCompileShader(shaderloc);
int error = gl.glGetError();
if(error != GL3.GL_NO_ERROR){
Logger.log(new GLU().gluErrorString(error), Logger.ERROR, "Shader compilation");
}
return shaderloc;
}
As an aside, the if statement towards the end where I check glGetError() isn't actually where the error gets caught, that doesn't happen until execution returns to the calling function and I check the shader logs. Could be relevant, but then again I could also be rambling.