how do i get a shader loaded into JOGL and check the status?
here’s my current code
public void setupshaders(GL gl)
{
String frag = "test.frag";
String vert ="test.vert";
int v = gl.glCreateShader(GL.GL_VERTEX_SHADER);
int f = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);
shader(gl,v,vert);
shader(gl,f,frag);
int shaderprogram = gl.glCreateProgram();
gl.glAttachShader(shaderprogram, v);
gl.glAttachShader(shaderprogram, f);
gl.glLinkProgram(shaderprogram);
gl.glValidateProgram(shaderprogram);
System.out.println(gl.glGetString(GL.GL_VERSION));
gl.glUseProgram(shaderprogram);
}
public void shader(GL gl, int shadernum, String file)
{
String fshadername=file;
BufferedReader shader= new BufferedReader(new InputStreamReader(new BufferedInputStream(getClass().getResourceAsStream(fshadername))));
String tempstring="";
Vector<String> shaderstringsvector= new Vector();
while(true)
{
try {
tempstring=shader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(tempstring==null)
{
break;
}
shaderstringsvector.add(tempstring);
}
String shaderstrings[]= new String[shaderstringsvector.size()];
int shaderlengths[]= new int[shaderstringsvector.size()];
for(int x=0;x<shaderstringsvector.size();x++)
{
shaderstrings[x]=shaderstringsvector.get(x);
shaderlengths[x]=shaderstringsvector.get(x).length();
}
gl.glShaderSource(shadernum, 1, shaderstrings, shaderlengths, 1);
gl.glCompileShader(shadernum);
}
}
how do i check the compile status and such? because i keep getting the exception
Exception in thread “AWT-EventQueue-0” javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glUseProgram(): GL_INVALID_OPERATION
at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:12715)
at javax.media.opengl.DebugGL.glUseProgram(DebugGL.java:9774)
at shaders.shader1.setupshaders(shader1.java:228)
at shaders.shader1.init(shader1.java:76)
at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:418)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:412)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:244)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:277)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
at java.awt.Component.dispatchEventImpl(Component.java:4486)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
what’s wrong here?