VBOs and Shaders in JOGL

So I got the hang of immediate mode drawing and tried doing some basic landscape rendering with it but was not pleased with the speed so I decided to try my hand with VBOs, then having conquered VBOs I decided to try adding shaders to that, and that’s where I ran into serious trouble. I’ve been trying the last few days to get the below code to work and it compiles fine, but opengl gives me a 1281 error

this code goes in the realmain class


import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.*;

import com.jogamp.opengl.util.FPSAnimator;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

public class RealMain{    
	public static void main(String[] args)    {        
		JFrame frame = new JFrame("JOGL test");
		frame.setSize(640, 480);
		GLProfile glProfile = GLProfile.getDefault();
		GLCapabilities glCapabilities = new GLCapabilities(glProfile); 
		GLCanvas canvas = new GLCanvas(glCapabilities);        
		frame.add(canvas);       
		canvas.addGLEventListener(new JOGLRenderer());   
		FPSAnimator animator = new FPSAnimator(canvas, 60);   
		animator.add(canvas); 
		animator.start();       
		frame.addWindowListener(new WindowAdapter(){           
			public void windowClosing(WindowEvent e)            {  
				System.exit(0);            }        });   
		frame.setVisible(true);   
	}   
	private static class JOGLRenderer implements GLEventListener    { 
		ShaderProgram shader;
		public void init(GLAutoDrawable drawable){



			shader = new ShaderProgram(drawable, new File("bin/vert.txt"), new File("bin/frag.txt"));

			//setup opengl
			GL3 gl = drawable.getGL().getGL3();       
			gl.glClearColor(0.2f, 0.2f, 0.0f, 0.0f);        
			gl.glClearDepth(1.0f);          
			gl.glEnable(GL.GL_DEPTH_TEST);         
			gl.glDepthFunc(GL.GL_LEQUAL);           
			gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);  

			// Create vertex data			
			float[] vertexData = new float[]{
					-1f, 1f, -2.0f, //0
					1f, 1f, -2.0f, //1
					-1f, -1f, -2.0f, //2
					1f, -1f, -2.0f, //3
			};
			ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(7 * 4 * 4);            
			vertexByteBuffer.order(ByteOrder.nativeOrder());      
			FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer();          
			vertexBuffer.put(vertexData);

			// Create vertex buffer     			
			int[] vertexBufferId = new int[1];			
			gl.glGenBuffers(1, vertexBufferId, 0);        
			gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexBufferId[0]);      
			gl.glBufferData(GL2.GL_ARRAY_BUFFER, 48, null, GL2.GL_DYNAMIC_DRAW); 
			// Load vertex data into vertex buffer			
			gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, vertexByteBuffer.capacity(), vertexByteBuffer);

			// Create index data           
			int[] indexData = new int[]{0, 1, 2, 3};

			ByteBuffer indexByteBuffer = ByteBuffer.allocateDirect(4 * 4);     
			indexByteBuffer.order(ByteOrder.nativeOrder());
			IntBuffer indexBuffer = indexByteBuffer.asIntBuffer();       
			indexBuffer.put(indexData);

			// Create index buffer     
			int[] indexBufferId = new int[1];      
			gl.glGenBuffers(1, indexBufferId, 0);
			gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferId[0]);          
			gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, 16, null, GL2.GL_DYNAMIC_DRAW);       
			// Load index data into index buffer          
			gl.glBufferSubData(GL2.GL_ELEMENT_ARRAY_BUFFER, 0, indexByteBuffer.capacity(), indexByteBuffer);

			

		}
		public void dispose(GLAutoDrawable drawable){} 
		public void display(GLAutoDrawable drawable){         
			GL3 gl = drawable.getGL().getGL3();   
			gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);       


			//gl.glMatrixMode(GL2.GL_MODELVIEW);
			//gl.glLoadIdentity();          
			int stride = 3 * 4; //3 floats per vert * 4 bytes per float


			
			gl.glVertexAttribPointer(gl.glGetAttribLocation(shader.p, "vertex"), 3, gl.GL_FLOAT, false, 20, 0);
			System.out.println(gl.glGetError()); 
			
			//shader code
			gl.glUseProgram(shader.p);
			gl.glDrawRangeElements(GL2.GL_TRIANGLE_STRIP, 0, 2, 3, GL2.GL_UNSIGNED_INT, 0); //start render at 0 verts go to 3 for a count of 4
			gl.glUseProgram(0);
		}    


		public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)        {          
			GL3 gl = drawable.getGL().getGL3();     
			GLU glu = new GLU(); 
			gl.glViewport(0, 0, width, height);   
			glu.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);  
		} 
	}
}



and this goes in shaderprogram


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
 
public class ShaderProgram {
	
    public ShaderProgram(GLAutoDrawable drawable, File vertf, File fragf) {
    	this.vertf = vertf;
    	this.fragf = fragf;
        GL3 gl = drawable.getGL().getGL3();
        
        int p = gl.glCreateProgram();
        
        
        //VERTEX STUFF
        int v = gl.glCreateShader(gl.GL_VERTEX_SHADER);
        
        ArrayList <String> vSourceA = new ArrayList<String>();
        Scanner vert = null;
		try {
			vert = new Scanner(vertf);
		} catch (FileNotFoundException e) {
			System.out.println("Vertex shader file was not found");
		}

		vert.useDelimiter("\n");
		
        while(vert.hasNext()){
        	String temp = vert.next() + "\n";
        	vSourceA.add(temp);
        	System.out.print(temp);
        }
        
        String[] vSource = new String[vSourceA.size()];
        vSource = vSourceA.toArray(vSource);
        int [] lengths= new int[vSource.length];
        for(int i = 0; i < vSource.length; i++){
        	lengths[i] = vSource[i].length();
        }
        
        gl.glShaderSource(v, lengths.length, vSource, lengths, 0);        
        gl.glCompileShader(v);
        gl.glAttachShader(p, v);
        
        //FRAGMENT SHADER CODE
        int f = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);
        
        ArrayList <String> fSourceA = new ArrayList<String>();
        
        Scanner frag = null;
		try {
			frag = new Scanner(fragf);
		} catch (FileNotFoundException e) {
			System.out.println("Fragment shader file was not found");
		}
		
		
		frag.useDelimiter("\n");
        while(frag.hasNext()){
        	String temp = frag.next() + "\n";
        	fSourceA.add(temp);
        	System.out.print(temp);
        }
        
        String[] fSource = new String[fSourceA.size()];
        fSource = fSourceA.toArray(fSource);
        lengths= new int[fSource.length];
        for(int i = 0; i < fSource.length; i++){
        	lengths[i] = fSource[i].length();
        }
        
        gl.glShaderSource(f, lengths.length, fSource, lengths, 0);        
        gl.glCompileShader(f);
        gl.glAttachShader(p, f);
        
        
        //PROGRAM CODE
        gl.glLinkProgram(p);
        gl.glValidateProgram(p);
        System.out.println(gl.glGetError());
        valid = true;
    }
 
    int p;
    boolean valid = false;
     
    File vertf;
    File fragf;
 
}

frag.txt


#version 150
out vec4 fragmentColor;
void
main()
{
    fragmentColor = vec4(0.0, 1.0, 0.0, 1.0);
}
";

vert.txt


#version 150
in vec3 vertex;
void
main()
{
    gl_Position = vec4(vertex,1.0);
}
";

Can you try wrapping your GL3 in a DebugGL3 before you perform any OpenGL operations, that way you’ll get an exception right where it fails and it will translate the int error code into a useful string.

Hm, I did not know that you could do that that’s neat.
So after wrapping gl with DebugGL3 it gives me this error message:


Exception in thread "Timer-0" javax.media.opengl.GLException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glBufferSubData(<int> 0x8892, <long>, <long>, <java.nio.Buffer>): GL_INVALID_VALUE ( 1281 0x501), 
	at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:98)
	at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:197)
	at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:164)
	at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:767)
	at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:388)
	at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:74)
	at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:140)
	at com.jogamp.opengl.util.FPSAnimator$1.run(FPSAnimator.java:125)
	at java.util.TimerThread.mainLoop(Unknown Source)
	at java.util.TimerThread.run(Unknown Source)
Caused by: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glBufferSubData(<int> 0x8892, <long>, <long>, <java.nio.Buffer>): GL_INVALID_VALUE ( 1281 0x501), 
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:12595)
	at javax.media.opengl.DebugGL3.glBufferSubData(DebugGL3.java:1409)
	at RealMain$JOGLRenderer.init(RealMain.java:72)
	at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:155)
	at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:175)
	at javax.media.opengl.awt.GLCanvas$InitAction.run(GLCanvas.java:856)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:356)
	at javax.media.opengl.awt.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:890)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


So looking at that error it looks like I managed to break my VBOs while trying to get shaders to work…

The error is at RealMain$JOGLRenderer.init(RealMain.java:72).
gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, vertexByteBuffer.capacity(), vertexByteBuffer);

I have a working demo using VBO and shaders to draw Mandelbrot things, I will compare this source code with yours tomorrow. Maybe something is wrong with the stride.

Yeah I got that, the error was caused by
ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(7 * 4 * 4);
which should have been
ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(3 * 4 * 4);
I’d forgotten to change the buffer size after I removed the color data from the vertices.

But now back to my broken shaders.
new error code is posted below:


Exception in thread "Timer-0" javax.media.opengl.GLException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glGetAttribLocation(<int> 0x0, <java.lang.String>): GL_INVALID_VALUE ( 1281 0x501), 
	at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:98)
	at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:197)
	at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:164)
	at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:767)
	at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:388)
	at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:74)
	at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:140)
	at com.jogamp.opengl.util.FPSAnimator$1.run(FPSAnimator.java:125)
	at java.util.TimerThread.mainLoop(Unknown Source)
	at java.util.TimerThread.run(Unknown Source)
Caused by: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glGetAttribLocation(<int> 0x0, <java.lang.String>): GL_INVALID_VALUE ( 1281 0x501), 
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:12595)
	at javax.media.opengl.DebugGL3.glGetAttribLocation(DebugGL3.java:5641)
	at RealMain$JOGLRenderer.display(RealMain.java:105)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:191)
	at javax.media.opengl.awt.GLCanvas$DisplayAction.run(GLCanvas.java:873)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:363)
	at javax.media.opengl.awt.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:890)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

and updated code for realmain is below


import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.*;

import com.jogamp.opengl.util.FPSAnimator;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

public class RealMain{    
	public static void main(String[] args)    {        
		JFrame frame = new JFrame("JOGL test");
		frame.setSize(640, 480);
		GLProfile glProfile = GLProfile.getDefault();
		GLCapabilities glCapabilities = new GLCapabilities(glProfile); 
		GLCanvas canvas = new GLCanvas(glCapabilities);        
		frame.add(canvas);       
		canvas.addGLEventListener(new JOGLRenderer());   
		FPSAnimator animator = new FPSAnimator(canvas, 60);   
		animator.add(canvas); 
		animator.start();       
		frame.addWindowListener(new WindowAdapter(){           
			public void windowClosing(WindowEvent e)            {  
				System.exit(0);            }        });   
		frame.setVisible(true);   
	}   
	private static class JOGLRenderer implements GLEventListener    { 
		ShaderProgram shader;
		public void init(GLAutoDrawable drawable){



			shader = new ShaderProgram(drawable, new File("bin/vert.txt"), new File("bin/frag.txt"));

			//setup opengl         
			DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());
			gl.glClearColor(0.2f, 0.2f, 0.0f, 0.0f);        
			gl.glClearDepth(1.0f);          
			gl.glEnable(GL3.GL_DEPTH_TEST);         

			// Create vertex data			
			float[] vertexData = new float[]{
					-1f, 1f, -2.0f, //0
					1f, 1f, -2.0f, //1
					-1f, -1f, -2.0f, //2
					1f, -1f, -2.0f, //3
			};
			ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(3 * 4 * 4);            
			vertexByteBuffer.order(ByteOrder.nativeOrder());      
			FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer();          
			vertexBuffer.put(vertexData);

			// Create vertex buffer     			
			int[] vertexBufferId = new int[1];			
			gl.glGenBuffers(1, vertexBufferId, 0);        
			gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferId[0]);      
			gl.glBufferData(GL3.GL_ARRAY_BUFFER, 48, (ByteBuffer)null, GL3.GL_DYNAMIC_DRAW); 
			// Load vertex data into vertex buffer			
			gl.glBufferSubData(GL3.GL_ARRAY_BUFFER, 0, vertexByteBuffer.capacity(), vertexByteBuffer);

			// Create index data           
			int[] indexData = new int[]{0, 1, 2, 3};

			ByteBuffer indexByteBuffer = ByteBuffer.allocateDirect(4 * 4);
			indexByteBuffer.order(ByteOrder.nativeOrder());
			IntBuffer indexBuffer = indexByteBuffer.asIntBuffer();
			indexBuffer.put(indexData);

			// Create index buffer     
			int[] indexBufferId = new int[1];
			gl.glGenBuffers(1, indexBufferId, 0);
			gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, indexBufferId[0]);          
			gl.glBufferData(GL3.GL_ELEMENT_ARRAY_BUFFER, 16, (ByteBuffer)null, GL3.GL_DYNAMIC_DRAW);       
			// Load index data into index buffer          
			gl.glBufferSubData(GL3.GL_ELEMENT_ARRAY_BUFFER, 0, indexByteBuffer.capacity(), indexByteBuffer);

			

		}
		public void dispose(GLAutoDrawable drawable){} 
		public void display(GLAutoDrawable drawable){         
			DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());
			gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);       


			//gl.glMatrixMode(GL2.GL_MODELVIEW);
			//gl.glLoadIdentity();          
			int stride = 3 * 4; //3 floats per vert * 4 bytes per float


			
			gl.glVertexAttribPointer(gl.glGetAttribLocation(shader.p, "vertex"), 3, GL3.GL_FLOAT, false, 20, 0);
			System.out.println(gl.glGetError()); 
			
			//shader code
			gl.glUseProgram(shader.p);
			gl.glDrawRangeElements(GL3.GL_TRIANGLE_STRIP, 0, 3, 4, GL3.GL_UNSIGNED_INT, 0); //start render at 0 verts go to 3 for a count of 4
			gl.glUseProgram(0);
		}    


		public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)        {          
			GL3 gl = drawable.getGL().getGL3();     
			GLU glu = new GLU(); 
			gl.glViewport(0, 0, width, height);   
			glu.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);  
		} 
	}
}

Right now I’m looking into the fact that my string for glGetAttribLocation is not null teminated

So in my ShaderProgram code I was assigning the program handle to a local variable facepalm but my program is still not working correctly, new error below



Exception in thread "Timer-0" javax.media.opengl.GLException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glGetAttribLocation(<int> 0x1, <java.lang.String>): GL_INVALID_OPERATION ( 1282 0x502), 
	at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:98)
	at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:197)
	at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:164)
	at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:767)
	at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:388)
	at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:74)
	at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:140)
	at com.jogamp.opengl.util.FPSAnimator$1.run(FPSAnimator.java:125)
	at java.util.TimerThread.mainLoop(Unknown Source)
	at java.util.TimerThread.run(Unknown Source)
Caused by: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glGetAttribLocation(<int> 0x1, <java.lang.String>): GL_INVALID_OPERATION ( 1282 0x502), 
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:12595)
	at javax.media.opengl.DebugGL3.glGetAttribLocation(DebugGL3.java:5641)
	at RealMain$JOGLRenderer.display(RealMain.java:105)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:191)
	at javax.media.opengl.awt.GLCanvas$DisplayAction.run(GLCanvas.java:873)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:363)
	at javax.media.opengl.awt.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:890)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

This makes me think that my shader program is not compiling successfully, but I’m not quite sure how to check that.

Here is the URL to the glGetAttribLocation documentation: http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml. In brief, you can get the GL_INVALID_OPERATION if the program wasn’t created by OpenGL, if it hasn’t been successfully linked (e.g. compiled) or if you’re calling it between glBegin and glEnd.

It sounds like you fixed the bug that would have made it the first cause, you can’t be doing the third, so you’re correct that you’re not getting your programs to link correctly.

Here is a link to my code for handling shaders: http://code.google.com/p/ferox-gl/source/browse/trunk/ferox-jogl/src/com/ferox/renderer/impl/jogl/JoglGlslShaderResourceDriver.java. It is part of an engine, but should be pretty easy to take what you need from it. You should pay the most attention to the glLinkProgram and glCompileShader methods defined in it.

Basically, you need to look up the compile status of each shader object, and the link status of the program object. The code also shows you how to query the information logs for both so you know why they might fail. The call glValidateProgram theoretically could be used to check if a program fails to link because it would fail to validate, but failing validation does not raise an opengl error that you can check with glGetError(), you’d have to check the VALIDATION_STATUS similarly to how I check the LINK_STATUS in the linked code.

Wow, that was super helpful, thank you very much.
So here’s the code that is compiled for each shader followed by the error it produces.
Since they both give the same error I’m thinking there’s something wrong with the way I’m reading in and feeding the code to openGL.


#version 150
in vec3 vertex;
void
main()
{
    gl_Position = vec4(vertex,1.0);
}
";
v: Vertex shader failed to compile with the following errors:
ERROR: 7:2: error(#90) Syntax error ERROR___CPP_EOL_IN_STRING
ERROR: 7:2: error(#132) Syntax error: '<' parse error
ERROR: error(#273) 2 compilation errors.  No code generated

#version 150
out vec4 fragmentColor;
void
main()
{
    fragmentColor = vec4(0.0, 1.0, 0.0, 1.0);
}
";
f: Fragment shader failed to compile with the following errors:
ERROR: 7:2: error(#90) Syntax error ERROR___CPP_EOL_IN_STRING
ERROR: 7:2: error(#132) Syntax error: '<' parse error
ERROR: error(#273) 2 compilation errors.  No code generated

for reference here’s my code that handles compiling the shaders (I commented out the linking related things for now)


public ShaderProgram(GLAutoDrawable drawable, File vertf, File fragf) {
		this.vertf = vertf;
		this.fragf = fragf;         
		DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());

		p = gl.glCreateProgram();

		//VERTEX STUFF
		int v = gl.glCreateShader(gl.GL_VERTEX_SHADER);

		ArrayList <String> vSourceA = new ArrayList<String>();
		Scanner vert = null;
		try {
			vert = new Scanner(vertf);
		} catch (FileNotFoundException e) {
			System.out.println("Vertex shader file was not found");
		}

		vert.useDelimiter("\n");

		while(vert.hasNext()){
			String temp = vert.next() + "\n";
			vSourceA.add(temp);
			System.out.print(temp);
		}

		String[] vSource = new String[vSourceA.size()];
		vSource = vSourceA.toArray(vSource);
		int [] lengths= new int[vSource.length];
		for(int i = 0; i < vSource.length; i++){
			lengths[i] = vSource[i].length();
		}

		gl.glShaderSource(v, lengths.length, vSource, lengths, 0);        
		gl.glCompileShader(v);

		// query compile status and possibly read log
		int[] status = new int[1];
		gl.glGetShaderiv(v, GL3.GL_COMPILE_STATUS, status, 0);
		if (status[0] == GL.GL_TRUE){
			System.out.println("v: succesful");
			// everything compiled successfully, no log
		}else{
			// compile failed, read the log and return it
			gl.glGetShaderiv(v, GL3.GL_INFO_LOG_LENGTH, status, 0);
			int maxLogLength = status[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetShaderInfoLog(v, maxLogLength, status, 0, log, 0);

				System.out.println("v: " + new String(log, 0, status[0]));
			} else
				System.out.println("v: "+ "unknown compilation error");
		}
		//FRAGMENT SHADER CODE
		int f = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);

		ArrayList <String> fSourceA = new ArrayList<String>();

		Scanner frag = null;
		try {
			frag = new Scanner(fragf);
		} catch (FileNotFoundException e) {
			System.out.println("Fragment shader file was not found");
		}


		frag.useDelimiter("\n");
		while(frag.hasNext()){
			String temp = frag.next() + "\n";
			fSourceA.add(temp);
			System.out.print(temp);
		}

		String[] fSource = new String[fSourceA.size()];
		fSource = fSourceA.toArray(fSource);
		lengths= new int[fSource.length];
		for(int i = 0; i < fSource.length; i++){
			lengths[i] = fSource[i].length();
		}

		gl.glShaderSource(f, lengths.length, fSource, lengths, 0);        
		gl.glCompileShader(f);

		// query compile status and possibly read log
		status = new int[1];
		gl.glGetShaderiv(f, GL3.GL_COMPILE_STATUS, status, 0);
		if (status[0] == GL.GL_TRUE){
			System.out.println("f: succesful");
			// everything compiled successfully, no log
		}else{
			// compile failed, read the log and return it
			gl.glGetShaderiv(f, GL3.GL_INFO_LOG_LENGTH, status, 0);
			int maxLogLength = status[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetShaderInfoLog(f, maxLogLength, status, 0, log, 0);
				System.out.println("f: " + new String(log, 0, status[0]));
			} else
				System.out.println("f: " + "unknown compilation error");
		}
		//PROGRAM CODE
		//gl.glLinkProgram(p);       
		//gl.glValidateProgram(p);


		valid = true;
	}

So I got the vertex and fragment shaders to compile by taking out the extra newline char I was adding in oops and taking out the #version line at the top. But now I have a different problem than before with glVertexAttribPointer


Exception in thread "Timer-0" javax.media.opengl.GLException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glVertexAttribPointer(<int> 0xFFFFFFFF, <int> 0x3, <int> 0x1406, <boolean>, <int> 0x0, <long>): GL_INVALID_VALUE ( 1281 0x501), 
	at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:98)
	at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:197)
	at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:164)
	at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:767)
	at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:388)
	at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:74)
	at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:140)
	at com.jogamp.opengl.util.FPSAnimator$1.run(FPSAnimator.java:125)
	at java.util.TimerThread.mainLoop(Unknown Source)
	at java.util.TimerThread.run(Unknown Source)
Caused by: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glVertexAttribPointer(<int> 0xFFFFFFFF, <int> 0x3, <int> 0x1406, <boolean>, <int> 0x0, <long>): GL_INVALID_VALUE ( 1281 0x501), 
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:12595)
	at javax.media.opengl.DebugGL3.glVertexAttribPointer(DebugGL3.java:8895)
	at RealMain$JOGLRenderer.display(RealMain.java:103)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:191)
	at javax.media.opengl.awt.GLCanvas$DisplayAction.run(GLCanvas.java:873)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:363)
	at javax.media.opengl.awt.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:890)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

current realmain code is below


import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.*;

import com.jogamp.opengl.util.FPSAnimator;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

public class RealMain{    
	public static void main(String[] args)    {        
		JFrame frame = new JFrame("JOGL test");
		frame.setSize(640, 480);
		GLProfile glProfile = GLProfile.getDefault();
		GLCapabilities glCapabilities = new GLCapabilities(glProfile); 
		GLCanvas canvas = new GLCanvas(glCapabilities);        
		frame.add(canvas);       
		canvas.addGLEventListener(new JOGLRenderer());   
		FPSAnimator animator = new FPSAnimator(canvas, 60);   
		animator.add(canvas); 
		animator.start();       
		frame.addWindowListener(new WindowAdapter(){           
			public void windowClosing(WindowEvent e)            {  
				System.exit(0);            }        });   
		frame.setVisible(true);   
	}   
	private static class JOGLRenderer implements GLEventListener    { 
		ShaderProgram shader;
		public void init(GLAutoDrawable drawable){



			shader = new ShaderProgram(drawable, new File("bin/vert.txt"), new File("bin/frag.txt"));

			//setup opengl         
			DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());
			gl.glClearColor(0.2f, 0.2f, 0.0f, 0.0f);        
			gl.glClearDepth(1.0f);          
			gl.glEnable(GL3.GL_DEPTH_TEST);         

			// Create vertex data			
			float[] vertexData = new float[]{
					-1f, 1f, -2.0f, //0
					1f, 1f, -2.0f, //1
					-1f, -1f, -2.0f, //2
					1f, -1f, -2.0f, //3
			};
			ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(3 * 4 * 4);            
			vertexByteBuffer.order(ByteOrder.nativeOrder());      
			FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer();          
			vertexBuffer.put(vertexData);

			// Create vertex buffer     			
			int[] vertexBufferId = new int[1];			
			gl.glGenBuffers(1, vertexBufferId, 0);        
			gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferId[0]);      
			gl.glBufferData(GL3.GL_ARRAY_BUFFER, 48, (ByteBuffer)null, GL3.GL_DYNAMIC_DRAW); 
			// Load vertex data into vertex buffer			
			gl.glBufferSubData(GL3.GL_ARRAY_BUFFER, 0, vertexByteBuffer.capacity(), vertexByteBuffer);

			// Create index data           
			int[] indexData = new int[]{0, 1, 2, 3};

			ByteBuffer indexByteBuffer = ByteBuffer.allocateDirect(4 * 4);
			indexByteBuffer.order(ByteOrder.nativeOrder());
			IntBuffer indexBuffer = indexByteBuffer.asIntBuffer();
			indexBuffer.put(indexData);

			// Create index buffer     
			int[] indexBufferId = new int[1];
			gl.glGenBuffers(1, indexBufferId, 0);
			gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, indexBufferId[0]);          
			gl.glBufferData(GL3.GL_ELEMENT_ARRAY_BUFFER, 16, (ByteBuffer)null, GL3.GL_DYNAMIC_DRAW);       
			// Load index data into index buffer          
			gl.glBufferSubData(GL3.GL_ELEMENT_ARRAY_BUFFER, 0, indexByteBuffer.capacity(), indexByteBuffer);



		}
		public void dispose(GLAutoDrawable drawable){} 
		public void display(GLAutoDrawable drawable){         
			DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());
			gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);       


			//gl.glMatrixMode(GL2.GL_MODELVIEW);
			//gl.glLoadIdentity();          
			int stride = 3 * 4; //3 floats per vert * 4 bytes per float

			gl.glVertexAttribPointer(gl.glGetAttribLocation(shader.p, "vertex"), 3, GL3.GL_FLOAT, false, 0, 0);

			//shader code
			gl.glUseProgram(shader.p);
			gl.glDrawRangeElements(GL3.GL_TRIANGLE_STRIP, 0, 3, 4, GL3.GL_UNSIGNED_INT, 0); //start render at 0 verts go to 3 for a count of 4
			gl.glUseProgram(0);
		}    


		public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)        {          
			GL3 gl = drawable.getGL().getGL3();     
			GLU glu = new GLU(); 
			gl.glViewport(0, 0, width, height);   
			glu.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);  
		} 
	}
}

In the stack trace, you can see that the glVertexAttribPointer was called with the value 0xffffff for the attribute index. This is equal to -1, which is an invalid value for glVertexAttribPointer. It also means that

glGetAttribLocation(shader.p, "vertex")

is returning -1, so there is still a problem with your shader code since OpenGL doesn’t think that “vertex” is an active attribute.

My hunch is that it is because you removed the version identifier. Unless you also updated the syntax of your shader, your syntax won’t quite match that of the default version 1.2 for GLSL shaders. Mainly, they don’t have “in vec3” you would need “attribute vec3”. It’s only a hunch, though, because I would have thought your card would fail to compile it.

However, I think I noticed an issue with your shader code that should allow you to put back the version identifier. In each vertex and fragment shader, you have the line: "; at the very end, which is invalid syntax. If you remove that, you should be able to compile the program fine with


#version 150

added back in. Of course, you might not support GLSL 1.5, but you should get error logs that report that instead of error logs saying that it failed to parse.

Wow, you beat me to it! I was about to point that out T_T

Okay so I fixed my shaders by removing the trailing ;, and modified my shader reading code to use nextline and added on \n to the end of each string in the source array and that made the shaders compiled without error, however when I try to attach the shaders and compile the program it says this:

Vertex shader(s) failed to link, fragment shader(s) failed to link.
ERROR: error(#280) Not all shaders have valid object code
ERROR: error(#280) Not all shaders have valid object code

Current shader code look like this


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;

import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;

public class ShaderProgram {

	public ShaderProgram(GLAutoDrawable drawable, File vertf, File fragf) {
		this.vertf = vertf;
		this.fragf = fragf;         
		DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());

		p = gl.glCreateProgram();

		//VERTEX STUFF
		int v = gl.glCreateShader(gl.GL_VERTEX_SHADER);

		ArrayList <String> vSourceA = new ArrayList<String>();
		Scanner vert = null;
		try {
			vert = new Scanner(vertf);
		} catch (FileNotFoundException e) {
			System.out.println("Vertex shader file was not found");
		}

		vert.useDelimiter("\n");
		while(vert.hasNextLine()){
			String temp = vert.nextLine() + "\n";
			vSourceA.add(temp);
			System.out.print(temp);
		}

		String[] vSource = new String[vSourceA.size()];
		vSource = vSourceA.toArray(vSource);
		int [] lengths= new int[vSource.length];
		for(int i = 0; i < vSource.length; i++){
			lengths[i] = vSource[i].length();
		}

		gl.glShaderSource(v, 1, vSource, lengths, 0);        
		gl.glCompileShader(v);
		gl.glAttachShader(p,v);

		// query compile status and possibly read log
		int[] status = new int[1];
		gl.glGetShaderiv(v, GL3.GL_COMPILE_STATUS, status, 0);
		if (status[0] == GL.GL_TRUE){
			System.out.println("v: succesful");
			// everything compiled successfully, no log
		}else{
			// compile failed, read the log and return it
			gl.glGetShaderiv(v, GL3.GL_INFO_LOG_LENGTH, status, 0);
			int maxLogLength = status[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetShaderInfoLog(v, maxLogLength, status, 0, log, 0);

				System.out.println("v: " + new String(log, 0, status[0]));
			} else
				System.out.println("v: "+ "unknown compilation error");
		}




		//FRAGMENT SHADER CODE
		int f = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);

		ArrayList <String> fSourceA = new ArrayList<String>();

		Scanner frag = null;
		try {
			frag = new Scanner(fragf);
		} catch (FileNotFoundException e) {
			System.out.println("Fragment shader file was not found");
		}


		frag.useDelimiter("\n");
		while(frag.hasNextLine()){
			String temp = frag.nextLine() + "\n";
			fSourceA.add(temp);
			System.out.print(temp);
		}

		String[] fSource = new String[fSourceA.size()];
		fSource = fSourceA.toArray(fSource);
		lengths= new int[fSource.length];
		for(int i = 0; i < fSource.length; i++){
			lengths[i] = fSource[i].length();
		}

		gl.glShaderSource(f, 1, fSource, lengths, 0);        
		gl.glCompileShader(f);
		gl.glAttachShader(p,f);

		// query compile status and possibly read log
		status = new int[1];
		gl.glGetShaderiv(f, GL3.GL_COMPILE_STATUS, status, 0);
		if (status[0] == GL.GL_TRUE){
			System.out.println("f: succesful");
			// everything compiled successfully, no log
		}else{
			// compile failed, read the log and return it
			gl.glGetShaderiv(f, GL3.GL_INFO_LOG_LENGTH, status, 0);
			int maxLogLength = status[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetShaderInfoLog(f, maxLogLength, status, 0, log, 0);
				System.out.println("f: " + new String(log, 0, status[0]));
			} else
				System.out.println("f: " + "unknown compilation error");
		}


		//PROGRAM CODE
		gl.glLinkProgram(p);       



		// check link status
		int[] query = new int[1];
		gl.glGetProgramiv(p, GL3.GL_LINK_STATUS, query, 0);
		if (query[0] == GL.GL_TRUE){
			System.out.println("P: successful"); // program linked successfully
			valid = true;
		}else{
			// link failed, read the log and return it
			gl.glGetProgramiv(p, GL3.GL_INFO_LOG_LENGTH, query, 0);
			int maxLogLength = query[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetProgramInfoLog(p, maxLogLength, query, 0, log, 0);

				valid = false;
				System.out.println(new String(log, 0, query[0]));
			} else{
				valid = false;
				System.out.println("unknown link error");
			}
		}
	}

	int p;
	boolean valid = false;

	File vertf;
	File fragf;

}

I do believe that error code is talking about your shader code, aka the C code.

I thought they were correct, they look like this:
vertex shader code


#version 150
in vec3 vertex;
void
main()
{
    gl_Position = vec4(vertex,1.0);
}

fragment shader code


#version 150
out vec4 fragmentColor;
void
main()
{
    fragmentColor = vec4(0.0, 1.0, 0.0, 1.0);
}

I barely know any C, but in the first one, where is vec3 used?
Also if vec4 is a function, where does it exist?

vec3 is the type of the input value vertex, and it’s used to set the position of the vertex.
And vec4 is saying that there is an output that has 4 pieces of data.

@ra4king: GLSL shader code is not C code, it has C like syntax. vec3 and vec4 are primitive data types in GLSL that represent 3 and 4 dimensional vectors. vec4(0.0, 1.0, 0.0, 1.0) does not call a function per se, it’s calling the constructor for the vec4.

When googling for “not all shaders have valid object code”, everyone who fixed it solved it by editing whitespace and newlines in their code. Every time this should not have made any difference, so its likely a bad compiler in the driver. I would suggest moving “void” and “main()” onto the same line and see if that gets you anywhere.

Yeah that doesn’t change anything, still getting the same
Vertex shader(s) failed to link, fragment shader(s) failed to link.
ERROR: error(#280) Not all shaders have valid object code
ERROR: error(#280) Not all shaders have valid object code
after the shaders report compiling successfully. sigh
I guess I’ll try updating my drivers and running it on a different computer.

EDIT:
The problem is definitely in the way I read in my shaders; hardcoding in the shaders as a string array makes everything compile fine (although I still need to figure out how to use them to draw)

So I fixed my shader compiling/linking/etc code and now glGetAttribLocation returns 0 (the first index) and the program compiles and runs without complaint, however all I’m getting right now is a screen drawn to the clearcolor.
Here’s my shader loading code for anyone trying to follow in my footsteps.


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.CharBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Scanner;

import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;

public class ShaderProgram {


	int p;
	boolean valid = false;

	File vertf;
	File fragf;
	
	String []vertS = {"#version 150\nin vec3 vertex;\nvoid main()\n{\ngl_Position = vec4(vertex,1.0);\n}"};
	String []fragS = {"#version 150\nout vec4 fragmentColor;\nvoid main()\n{\nfragmentColor = vec4(0.0, 1.0, 0.0, 1.0);\n}"};
	
	public ShaderProgram(GLAutoDrawable drawable, File vertf, File fragf) {
		this.vertf = vertf;
		this.fragf = fragf;         
		DebugGL3 gl = new DebugGL3( drawable.getGL().getGL3());

		p = gl.glCreateProgram();

		int v = gl.glCreateShader(gl.GL_VERTEX_SHADER);		
		int f = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);
		readAndCompileShader(v, vertf, gl);
		readAndCompileShader(f, fragf, gl);

		gl.glLinkProgram(p);       



		// check link status
		int[] query = new int[1];
		gl.glGetProgramiv(p, GL3.GL_LINK_STATUS, query, 0);
		if (query[0] == GL.GL_TRUE){
			System.out.println("P: successful"); // program linked successfully
			valid = true;
		}else{
			// link failed, read the log and return it
			gl.glGetProgramiv(p, GL3.GL_INFO_LOG_LENGTH, query, 0);
			int maxLogLength = query[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetProgramInfoLog(p, maxLogLength, query, 0, log, 0);

				valid = false;
				System.out.println(new String(log, 0, query[0]));
			} else{
				valid = false;
				System.out.println("unknown link error");
			}
		}
	}
	
	void readAndCompileShader(int shader, File sourceF, DebugGL3 gl){
		String [] source = new String[1];
		try {
			source[0] = readFile(sourceF);
		} catch (IOException e) {
			System.out.println("Could not find shader file");
		}
		source[0] = source[0].replaceAll("\r\n", "\n");
		//System.out.print(source[0]);
		
		int[] lengths = new int[]{source[0].length()};

		gl.glShaderSource(shader, 1, source, lengths, 0);        
		gl.glCompileShader(shader);
		gl.glAttachShader(p,shader);

		// query compile status and possibly read log
		int[] status = new int[1];
		gl.glGetShaderiv(shader, GL3.GL_COMPILE_STATUS, status, 0);
		if (status[0] == GL.GL_TRUE){
			System.out.println("shader: succesful");
			// everything compiled successfully, no log
		}else{
			// compile failed, read the log and return it
			gl.glGetShaderiv(shader, GL3.GL_INFO_LOG_LENGTH, status, 0);
			int maxLogLength = status[0];
			if (maxLogLength > 0) {
				byte[] log = new byte[maxLogLength];
				gl.glGetShaderInfoLog(shader, maxLogLength, status, 0, log, 0);

				System.out.println("shader: " + new String(log, 0, status[0]));
			} else
				System.out.println("shader: "+ "unknown compilation error");
		}
	}
	
	private static String readFile(File file) throws IOException {
		  FileInputStream stream = new FileInputStream(file);
		  try {
		    FileChannel fc = stream.getChannel();
		    MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
		    /* Instead of using default, pass in a decoder. */
		    return Charset.forName("UTF-8").decode(bb).toString();
		  }
		  finally {
		    stream.close();
		  }
		}
}

It might not be showing up because I think your modelview and project matrices are setup incorrectly. Before you call gluPerspective, you should call glMatrixMode(GL_PROJECTION); glLoadIdentity(). Then after that call to gluPerspective, you should call glMatrixMode(GL_MODELVIEW) to switch back.

Having the projection matrix embedded in the modelview matrix usually screws things up and puts the vertices somewhere entirely unexpected.