Hi everybody!
I have worked quite a while with JOGL and Cg now and I now tried to look into OpenGL Shading Laguage. I found a few tutorials, wrote some shaders using a shader-designer-software and started porting some C-code to Java/JOGL to have the shaders running there.
Now after doing all this I get nothing at all. I implemented an output for the InfoLog and get the following output:
Vertex info
-----------
(0) : error C3001: no program defined
1 lines, 1 errors.
Fragment info
-------------
(0) : error C3001: no program defined
1 lines, 1 errors.
If I try and compile the shaders with the cgc-compiler and the option “-oglsl” everythings works fine. I get no errors.
The shaders are:
public String[] getVertexShader() {
String[] result = new String[8];
result[0] = new String("varying vec3 v;");
result[1] = new String("varying vec3 n;");
result[2] = new String("void main() {");
result[3] = new String("v = vec3(gl_ModelViewMatrix * gl_Vertex);");
result[4] = new String("n = normalize(gl_NormalMatrix * gl_Normal);");
result[5] = new String("gl_TexCoord[0] = gl_MultiTexCoord0;");
result[6] = new String("gl_TexCoord[1] = gl_MultiTexCoord0;");
result[7] = new String("gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }");
return result;
}
public String[] getFragmentShader() {
String[] result = new String[14];
result[0] = new String("varying vec3 v;");
result[1] = new String("varying vec3 n;");
result[2] = new String("uniform sampler2D TextureUnit0;");
result[3] = new String("void main() {");
result[4] = new String("vec4 ambient, diffuse, specular;");
result[5] = new String("for (int l = 0; l < gl_MaxLights; l++) {");
result[6] = new String("vec3 l = normalize(gl_LightSource[l].position.xyz - v);");
result[7] = new String("vec3 e = normalize(-v);");
result[8] = new String("vec3 r = normalize(-reflect(l, n));");
result[9] = new String("ambient += gl_FrontLightProduct[l].ambient * gl_FrontMaterial.ambient;");
result[10] = new String("diffuse += gl_FrontLightProduct[l].diffuse * max(dot(n, l), 0.0);");
result[11] = new String("specular += gl_FrontLightProduct[l].specular * pow(max(dot(r, e), 0.0), gl_FrontMaterial.shininess); }");
result[12] = new String("gl_FragColor = ambient + diffuse;");
result[13] = new String("gl_FragColor += specular; }");
return result;
}
The code to initi GLSL and load the programs looks like this:
protected void initGLSL(GLDrawable glDraw) {
GL gl = glDraw.getGL();
this.vertexShaderHandle = gl.glCreateShaderObjectARB(GL.GL_VERTEX_SHADER_ARB);
this.fragmentShaderHandle = gl.glCreateShaderObjectARB(GL.GL_FRAGMENT_SHADER_ARB);
FirstGLSLshader shaderSource = new FirstGLSLshader();
int[] emptyIntArray = null;
gl.glShaderSourceARB(this.vertexShaderHandle, 1, shaderSource.getVertexShader(), emptyIntArray);
gl.glShaderSourceARB(this.fragmentShaderHandle, 1, shaderSource.getFragmentShader(), emptyIntArray);
gl.glCompileShaderARB(this.vertexShaderHandle);
int[] resultVertex = new int[1];
gl.glGetObjectParameterivARB(this.vertexShaderHandle, GL.GL_OBJECT_COMPILE_STATUS_ARB, resultVertex);
this.printInfoLog(glDraw, this.vertexShaderHandle);
gl.glCompileShaderARB(this.fragmentShaderHandle);
int[] resultFragment = new int[1];
gl.glGetObjectParameterivARB(this.fragmentShaderHandle, GL.GL_OBJECT_COMPILE_STATUS_ARB, resultFragment);
this.printInfoLog(glDraw, this.fragmentShaderHandle);
if (resultVertex[0] == 0 || resultFragment[0] == 0) {
if (VERBOSE) System.err.println("Unable to initialize OGSL");
System.exit(-1);
}
this.OGSLProgram = gl.glCreateProgramObjectARB();
gl.glAttachObjectARB(this.OGSLProgram, this.vertexShaderHandle);
gl.glAttachObjectARB(this.OGSLProgram, this.fragmentShaderHandle);
gl.glLinkProgramARB(this.OGSLProgram);
int[] programLinked = new int[1];
gl.glGetObjectParameterivARB(this.fragmentShaderHandle, GL.GL_OBJECT_COMPILE_STATUS_ARB, programLinked);
this.printInfoLog(glDraw, this.OGSLProgram);
if (programLinked[0] == 0) {
if (VERBOSE) System.err.println("Unable to link Program");
System.exit(-1);
}
gl.glUseProgramObjectARB(this.OGSLProgram);
this.checkGLErrors(glDraw);
}
I’m not quite sure where the problem is. Is there a need to specify the entry-point-function-names? I though that wouldn’t be necessary if they are both “main”.
The cgc-compiler I used for testing the code is from the new Cg-Toolkit 1.3 Beta 2. Hardware is a nVidia Quadro FX 3400 with drivers 65.62 (Dell Performance-Driver).
Anybody got an idea? Any help is appreciated.
Greetz…
…Hoschi_S