Skip to main content
changed title, added efforts to switch to glDrawArrays
Source Link

Texturing a VBO cube using glDrawElements (JOGL)

I've been having trouble texturing a cube using vertex buffer objects. I got the cube up and running, and my program compiles, but the texture does not appear. I think my problem may be my GLSL in my shaders.

I got a vertex shader and a fragment shader up and running. The fragment shader was working when it was just making it a color, but I can't get it to texture an image.

EDIT2EDIT2: I simplified the shaders so I could figure out setting uniforms first. The program runs, but the VBO doesn't have any texture on it. Many examples I've seen do basically the same thing I am (I think). So I think the problem now could be something small or obvious that I'm not seeing.

EDIT3: Now I've been trying to convert from drawElements to drawArrays. I simplifiedcan't get the shaders so I could figure out setting uniforms firstcube to render let alone render with textures. The program runsWhen I run this, there are clearly triangles being rendered, but I can't relate their position to the VBO doesn't have any texture on itvertex array. Many examples I've seen do basicallyFor example, some of the same thing I am (I think)triangles have points at 0,0,0 and there are no points 0,0,0 in vertexArray. So I think the problem now couldI may be something smallmissing some glDrawArrays syntax or obviousI left something from glDrawElements that I'm not seeingshouldn't be there.

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        

// cube ///////////////////////////////////////////////////////////////////////
//      v6----- v5
  //   /|      /|
  //  v1------v0|
  //  | |     | |
  //  | |v7---|-|v4
  //  |/      |/
  //  v2------v3

  // vertex coords array for glDrawArrays() =====================================
  // A cube has 6 sides and each side has 2 triangles, therefore, a cube consists
  // of 36 vertices (6 sides * 2 tris * 3 vertices = 36 vertices). And, each
  // vertex is 3 components (x,y,z) of floats, therefore, the size of vertex
  // array is 108 floats (36 * 3 = 108).
        
  float[] vertexArray = { 1, 1, 1,  -1, 1, 1,  -1,-1, 1,      // v0-v1-v2 (front)
                 0, 0       -1,-1, 01,
    1,-1, 1,   1, 1, 1,      // v2-v3-v0

                          1, 1, 1,   1,-x1, x1, x  1,-1,-1,      // v0-v3-v4 (right)
                 x         1,-1,-1, x  1, x1,-1,   1, 1, 1,      // v4-v5-v0

                          1, 1, 1,   1, 1,-x1,  -x1, x1,-1,      // v0-v5-v6 (top)
                 x        -1, 1,-x1, x -1, 1, 1,   1, 1, 1,      // v6-v1-v0

                         -1, 1, 1,  -1, 1,-1,  -1,-1,-1,      // v1-v6-v7 (left)
                         -x1,-1,-1, x -1,-x1, 1,  -1, 1, 1,      // v7-v2-v1

                 x        -1,-1,-1, x  1,-x1,-1,   1,-1, 1,      // v7-v4-v3 (bottom)
                          1,-x1, 1,  -x1,-x1, 1,  -1,-1,-1,      // v3-v2-v7

                 x         1,-x1,-x1,  -1,-1,-1,  -1, 1,-1,      // v4-v7-v6 (back)
                 
         -1, 1,-1,   1, 1,-1,   1,-1,-1 };    // v6-v5-v4

        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
            textureData.put(textureLeft);
            textureData.put(textureRight);
            textureData.put(textureBottom);
            textureData.put(textureTop);
            textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
                * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
        
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFERGL_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFERGL_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);GL_STAT

IC_DRAW);
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
            
            shader = new Shader(gl);
            shader.bind(gl);
            shader.attachVertexShader(gl);
            shader.attachFragmentShader(gl);
            shader.link(gl);
            //shader.unbind(gl);
        }
        
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   

 //shader.bind(gl);
    
    //initializing textures
    this.textureFileName = textureFileName;
    this.textureFileType = textureFileType;
    

       loadTexture(gl);
    texture.enable(gl);
    shadergl.bindglEnable(glGL.GL_TEXTURE_2D);  

    //setting the uniform
  this  shader.textureFileNamesetUniform(gl, ="tex", textureFileName;0);  
    
    //activating textures
 this   gl.textureFileTypeglActiveTexture(GL2.GL_TEXTURE0 =+ textureFileType;0);
    texture.bind(gl);    loadTexture  
    
    //drawing
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
     
    texture/* Setup Position Pointer */
    gl.enableglBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
    gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
     
    texture/* Setup Texture Coordinate Pointer */
    gl.bindglBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
    gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
    
//actual drawing
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
gl.glDrawArrays(GL.GL_TRIANGLES, (int) vertices.get(0), vertices.capacity());

        gl.glActiveTextureglDisableClientState(GLGL2.GL_TEXTURE0GL_TEXTURE_COORD_ARRAY);
        shadergl.setUniformglDisableClientState(gl, "tex", 0GL2.GL_VERTEX_ARRAY);
                    
      

          gl.glEnable(GL.GL_TEXTURE_2D);           
                
          gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
          gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
            
            /* Setup Position Pointer */
            gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
            
            /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
            gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
            
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawElements(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }

Texturing a VBO cube using glDrawElements (JOGL)

I've been having trouble texturing a cube using vertex buffer objects. I got the cube up and running, and my program compiles, but the texture does not appear. I think my problem may be my GLSL in my shaders.

I got a vertex shader and a fragment shader up and running. The fragment shader was working when it was just making it a color, but I can't get it to texture an image.

EDIT2: I simplified the shaders so I could figure out setting uniforms first. The program runs, but the VBO doesn't have any texture on it. Many examples I've seen do basically the same thing I am (I think). So I think the problem now could be something small or obvious that I'm not seeing.

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        float[] vertexArray = {
                 0, 0, 0,
                 
                -x, x, x,
                 x, x, x,
                -x,-x, x, 
                 x,-x, x,
                 
                -x, x,-x,
                 x, x,-x,
                -x,-x,-x, 
                 x,-x,-x,
                 
         };
        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
            textureData.put(textureLeft);
            textureData.put(textureRight);
            textureData.put(textureBottom);
            textureData.put(textureTop);
            textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
                * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
        
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

        shader = new Shader(gl);
        shader.attachVertexShader(gl);
        shader.attachFragmentShader(gl);
        shader.link(gl);
    }
        
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   


       
        shader.bind(gl);

        this.textureFileName = textureFileName;
        this.textureFileType = textureFileType;
        loadTexture(gl);
        texture.enable(gl);
        texture.bind(gl);

        gl.glActiveTexture(GL.GL_TEXTURE0);
        shader.setUniform(gl, "tex", 0);
                    
      

          gl.glEnable(GL.GL_TEXTURE_2D);           
                
          gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
          gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
            
            /* Setup Position Pointer */
            gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
            
            /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
            gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
            
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawElements(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }

Texturing a VBO cube (JOGL)

I've been having trouble texturing a cube using vertex buffer objects.

EDIT2: I simplified the shaders so I could figure out setting uniforms first. The program runs, but the VBO doesn't have any texture on it. Many examples I've seen do basically the same thing I am (I think). So I think the problem now could be something small or obvious that I'm not seeing.

EDIT3: Now I've been trying to convert from drawElements to drawArrays. I can't get the cube to render let alone render with textures. When I run this, there are clearly triangles being rendered, but I can't relate their position to the vertex array. For example, some of the triangles have points at 0,0,0 and there are no points 0,0,0 in vertexArray. I think I may be missing some glDrawArrays syntax or I left something from glDrawElements that shouldn't be there.

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        

// cube ///////////////////////////////////////////////////////////////////////
//      v6----- v5
  //   /|      /|
  //  v1------v0|
  //  | |     | |
  //  | |v7---|-|v4
  //  |/      |/
  //  v2------v3

  // vertex coords array for glDrawArrays() =====================================
  // A cube has 6 sides and each side has 2 triangles, therefore, a cube consists
  // of 36 vertices (6 sides * 2 tris * 3 vertices = 36 vertices). And, each
  // vertex is 3 components (x,y,z) of floats, therefore, the size of vertex
  // array is 108 floats (36 * 3 = 108).
        
  float[] vertexArray = { 1, 1, 1,  -1, 1, 1,  -1,-1, 1,      // v0-v1-v2 (front)
                         -1,-1, 1,   1,-1, 1,   1, 1, 1,      // v2-v3-v0

                          1, 1, 1,   1,-1, 1,   1,-1,-1,      // v0-v3-v4 (right)
                          1,-1,-1,   1, 1,-1,   1, 1, 1,      // v4-v5-v0

                          1, 1, 1,   1, 1,-1,  -1, 1,-1,      // v0-v5-v6 (top)
                         -1, 1,-1,  -1, 1, 1,   1, 1, 1,      // v6-v1-v0

                         -1, 1, 1,  -1, 1,-1,  -1,-1,-1,      // v1-v6-v7 (left)
                         -1,-1,-1,  -1,-1, 1,  -1, 1, 1,      // v7-v2-v1

                         -1,-1,-1,   1,-1,-1,   1,-1, 1,      // v7-v4-v3 (bottom)
                          1,-1, 1,  -1,-1, 1,  -1,-1,-1,      // v3-v2-v7

                          1,-1,-1,  -1,-1,-1,  -1, 1,-1,      // v4-v7-v6 (back)
                         -1, 1,-1,   1, 1,-1,   1,-1,-1 };    // v6-v5-v4

        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
        textureData.put(textureLeft);
        textureData.put(textureRight);
        textureData.put(textureBottom);
        textureData.put(textureTop);
        textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
        
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STAT

IC_DRAW);
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
            
            shader = new Shader(gl);
            shader.bind(gl);
            shader.attachVertexShader(gl);
            shader.attachFragmentShader(gl);
            shader.link(gl);
            //shader.unbind(gl);
        }
        
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   

 //shader.bind(gl);
    
    //initializing textures
    this.textureFileName = textureFileName;
    this.textureFileType = textureFileType;
    

loadTexture(gl);
    texture.enable(gl);
    gl.glEnable(GL.GL_TEXTURE_2D);  

    //setting the uniform
    shader.setUniform(gl, "tex", 0);  
    
    //activating textures
    gl.glActiveTexture(GL2.GL_TEXTURE0 + 0);
    texture.bind(gl);      
    
    //drawing
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
     
    /* Setup Position Pointer */
    gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
    gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
     
    /* Setup Texture Coordinate Pointer */
    gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
    gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
    
//actual drawing
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
gl.glDrawArrays(GL.GL_TRIANGLES, (int) vertices.get(0), vertices.capacity());

gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

//shader.unbind(gl);
       
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }
simplified shaders
Source Link

EDITEDIT: I updated/replaced my shaders to fit the right version. The program compiles and links, but it shuts down java in drawCubeVBO().

EDIT2: I updated/replaced my shaders to fitsimplified the right versionshaders so I could figure out setting uniforms first. The program compiles and linksruns, but the VBO doesn't have any texture on it shuts down java in drawCubeVBO. Many examples I've seen do basically the same thing I am (I think). So I think the problem now could be something small or obvious that I'm not seeing.

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        float[] vertexArray = {
                 0, 0, 0,
                
                -x, x, x,
                 x, x, x,
                -x,-x, x, 
                 x,-x, x,
                 
                -x, x,-x,
                 x, x,-x,
                -x,-x,-x, 
                 x,-x,-x,
                 
        };
        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
            textureData.put(textureLeft);
            textureData.put(textureRight);
            textureData.put(textureBottom);
            textureData.put(textureTop);
            textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
                * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
        
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

        shader = new Shader(gl);
        shader.attachVertexShader(gl);
        shader.attachFragmentShader(gl);
        shader.link(gl);
    }
        
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   
 

     //I'm not sure 
 if this belongs in this method or in initVBOshader.bind(gl);
     
        this.textureFileName = textureFileName;
            this.textureFileType = textureFileType;
            loadTexture(gl);
            texture.enable(gl);
                texture.bind(gl); 

        gl.glActiveTexture(GL.GL_TEXTURE0);
        shader.bindsetUniform(gl, "tex", 0);
                    
       

          gl.glEnable(GL.GL_TEXTURE_2D);           
                
                gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
                gl.glEnableClientState
    
    (GL2.GL_TEXTURE_COORD_ARRAY);
            
            /* Setup Position Pointer */
            gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
            
            /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
            gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
            
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawEleme

ntsglDrawElements(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }
private String vertexShaderString =
            "#version 330\n"+
             
            "layout (std140) uniform Matrices {\n"+
                "mat4 m_pvm;\n"+
                "mat4 m_viewModel;\n"+
                "mat3 m_normal;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in vec4 position;\n"+   // local space
            "in vec3 normal;\n"+     // local space
            "in vec2 texCoord;\n"+
             
            // the data to be sent to the fragment shader
            "out Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataOut;\n"+
             
            "void main () {\n"+
             
                "DataOut.normal = normalize(m_normal * normal);\n"+
                "DataOut.eye = -(m_viewModel * position);\n"+
                "DataOut.texCoord = texCoord;\n"+
             
                "gl_Position = m_pvm * position;\n"+
           330 "}";core\n"+

    private String fragmentShaderString = 
            "#version 330\n"+
             
            "layout (std140) uniform Material {\n"+
                "vec4 diffuse;\n"+
                "vec4 ambient;\n"+
                "vec4 specular;\n"+
                "float shininess;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataIn;\n"+
             
            "uniform sampler2D texUnit;\n"+
             
            "out vec4 colorOut;\n"+
             
            "void main() {\n"+
             
                // set the specular term to black
                "vec4 spec = vec4(0.0);\n"+
             
                // normalize both input vectors
                "vec3 n = normalize(DataIn.normal);\n"+
                "vec3 e = normalize(vec3(DataIn.eye));\n"+
             
                "float intensity = max(dot(n,l_dir), 0.0);\n"+
             
                // if the vertex is lit compute the specular color
                "if (intensity > 0.0) {\n"+
                    // compute the half vector
                    "vec3 h = normalize(l_dir + e);\n"+
                    // compute the specular term into spec
                    "float intSpeclocation = max(dot(h,n), 0.0);\n"+
                    "spec = specular * pow(intSpec,shininess);\n"+
              in vec2 "}\n"+pos;\n"+
                "vec4 texColor = texture"layout(texUnit, DataIn.texCoord);\n"+
                "vec4 diffColor = intensity *  diffuse * texColor;\n"+
                "vec4 ambColor = ambient * texColor;\n"+
             
                "colorOutlocation = max(diffColor + spec, ambColor1);\n"+
          in vec2 "}";tex;\n"+

        "out vec2 texCoords;\n"+

        "void main()\n"+
        "{\n"+
            "texCoords = tex;\n"+
            "gl_Position = vec4(pos, 0.0, 1.0);\n"+
        "}";

private String fragmentShaderString = 
        "#version 330 core\n"+

        "uniform sampler2D tex;\n"+

        "in vec2 texCoords;\n"+
        "out vec4 outColor;\n"+

        "void main()\n"+
        "{\n"+
            "outColor = texture(tex, texCoords);\n"+
        "}";


    // ProgramID
    int programID;

    // Vertex Shader ID
    int vertexShaderID;

    // Fragment Shader ID
    int fragmentShaderID;

    public Shader(GL2ES2 gl) {
        programID = gl.glCreateProgram();
    }

    public void attachVertexShader(GL2ES2 gl) {
        
        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        vertexShaderID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { vertexShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(vertexShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(vertexShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! vertex shader compiled");}
        else {
            int[] logLength = new int[1];
            gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(vertexShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the vertex shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, vertexShaderID);
    }

    public void attachFragmentShader(GL2ES2 gl) {

        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        fragmentShaderID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { fragmentShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(fragmentShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(fragmentShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! fragment shader compiled");}
        else {  
            int[] logLength = new int[1];
            gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(fragmentShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the fragment shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, fragmentShaderID);
        
    }



public void link(GL2ES2 gl) {
    
    public void link(GL2ES2 gl) {
        
        //link
        gl.glLinkProgram(programID);
        
        
        //check for errors
        int[] compiled = new int[1];
        gl.glGetProgramiv(programID, GL2ES2.GL_LINK_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! Shader program linked!");}
        else {
            int[] logLength = new int[1];
            gl.glGetProgramiv(programID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetProgramInfoLog(programID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error linking the program: " + new String(log));
   

          System.exit(1);
        }

/**
 * Sets the uniforms in this shader
 * 
 * @param name    The name of the uniform
 * @param values  The values of the uniforms (Max 4)
 */
public void setUniform(GL2ES2 gl, String name, float... values)
{
    if (values.length > 4)
    {
        System.err.println("Uniforms cannot have more than 4 values");
        System.exit(1);
    }
    
    // Get the location of the uniform
    int location = gl.glGetUniformLocation(programID, name);
    
    // Set the uniform values
    switch (values.length)
    {
        case 1:
            gl.glUniform1f(location, values[0]);
            break;                
        case 2:
            gl.glUniform2f(location, values[0], values[1]);
            break;                
        case 3:
            gl.glUniform3f(location, values[0], values[1], values[2]);
            break;                
        case 4:
            gl.glUniform4f(location, values[0], values[1], values[2], values[3]);
            break;
    }
}

EDIT: I updated/replaced my shaders to fit the right version. The program compiles and links, but it shuts down java in drawCubeVBO().

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        float[] vertexArray = {
                 0, 0, 0,
                
                -x, x, x,
                 x, x, x,
                -x,-x, x, 
                 x,-x, x,
                 
                -x, x,-x,
                 x, x,-x,
                -x,-x,-x, 
                 x,-x,-x,
                 
        };
        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
            textureData.put(textureLeft);
            textureData.put(textureRight);
            textureData.put(textureBottom);
            textureData.put(textureTop);
            textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
                * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
        
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

        shader = new Shader(gl);
        shader.attachVertexShader(gl);
        shader.attachFragmentShader(gl);
        shader.link(gl);
    }
        
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   
     //I'm not sure if this belongs in this method or in initVBO
            this.textureFileName = textureFileName;
            this.textureFileType = textureFileType;
            loadTexture(gl);
            texture.enable(gl);
                texture.bind(gl);
        
        shader.bind(gl);        
                gl.glEnable(GL.GL_TEXTURE_2D);           
                
                gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
                gl.glEnableClientState
    
    (GL2.GL_TEXTURE_COORD_ARRAY);
            
            /* Setup Position Pointer */
            gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
            
            /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
            gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
            
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawEleme

nts(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }
private String vertexShaderString =
            "#version 330\n"+
             
            "layout (std140) uniform Matrices {\n"+
                "mat4 m_pvm;\n"+
                "mat4 m_viewModel;\n"+
                "mat3 m_normal;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in vec4 position;\n"+   // local space
            "in vec3 normal;\n"+     // local space
            "in vec2 texCoord;\n"+
             
            // the data to be sent to the fragment shader
            "out Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataOut;\n"+
             
            "void main () {\n"+
             
                "DataOut.normal = normalize(m_normal * normal);\n"+
                "DataOut.eye = -(m_viewModel * position);\n"+
                "DataOut.texCoord = texCoord;\n"+
             
                "gl_Position = m_pvm * position;\n"+
            "}";

    private String fragmentShaderString = 
            "#version 330\n"+
             
            "layout (std140) uniform Material {\n"+
                "vec4 diffuse;\n"+
                "vec4 ambient;\n"+
                "vec4 specular;\n"+
                "float shininess;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataIn;\n"+
             
            "uniform sampler2D texUnit;\n"+
             
            "out vec4 colorOut;\n"+
             
            "void main() {\n"+
             
                // set the specular term to black
                "vec4 spec = vec4(0.0);\n"+
             
                // normalize both input vectors
                "vec3 n = normalize(DataIn.normal);\n"+
                "vec3 e = normalize(vec3(DataIn.eye));\n"+
             
                "float intensity = max(dot(n,l_dir), 0.0);\n"+
             
                // if the vertex is lit compute the specular color
                "if (intensity > 0.0) {\n"+
                    // compute the half vector
                    "vec3 h = normalize(l_dir + e);\n"+
                    // compute the specular term into spec
                    "float intSpec = max(dot(h,n), 0.0);\n"+
                    "spec = specular * pow(intSpec,shininess);\n"+
                "}\n"+
                "vec4 texColor = texture(texUnit, DataIn.texCoord);\n"+
                "vec4 diffColor = intensity *  diffuse * texColor;\n"+
                "vec4 ambColor = ambient * texColor;\n"+
             
                "colorOut = max(diffColor + spec, ambColor);\n"+
            "}";


    // ProgramID
    int programID;

    // Vertex Shader ID
    int vertexShaderID;

    // Fragment Shader ID
    int fragmentShaderID;

    public Shader(GL2ES2 gl) {
        programID = gl.glCreateProgram();
    }

    public void attachVertexShader(GL2ES2 gl) {
        
        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        vertexShaderID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { vertexShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(vertexShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(vertexShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! vertex shader compiled");}
        else {
            int[] logLength = new int[1];
            gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(vertexShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the vertex shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, vertexShaderID);
    }

    public void attachFragmentShader(GL2ES2 gl) {

        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        fragmentShaderID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { fragmentShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(fragmentShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(fragmentShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! fragment shader compiled");}
        else {  
            int[] logLength = new int[1];
            gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(fragmentShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the fragment shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, fragmentShaderID);
        
    }
    
    public void link(GL2ES2 gl) {
        
        //link
        gl.glLinkProgram(programID);
        
        
        //check for errors
        int[] compiled = new int[1];
        gl.glGetProgramiv(programID, GL2ES2.GL_LINK_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! Shader program linked!");}
        else {
            int[] logLength = new int[1];
            gl.glGetProgramiv(programID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetProgramInfoLog(programID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error linking the program: " + new String(log));
            System.exit(1);
        }

EDIT: I updated/replaced my shaders to fit the right version. The program compiles and links, but it shuts down java in drawCubeVBO().

EDIT2: I simplified the shaders so I could figure out setting uniforms first. The program runs, but the VBO doesn't have any texture on it. Many examples I've seen do basically the same thing I am (I think). So I think the problem now could be something small or obvious that I'm not seeing.

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        float[] vertexArray = {
                 0, 0, 0,
                
                -x, x, x,
                 x, x, x,
                -x,-x, x, 
                 x,-x, x,
                 
                -x, x,-x,
                 x, x,-x,
                -x,-x,-x, 
                 x,-x,-x,
                 
        };
        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
            textureData.put(textureLeft);
            textureData.put(textureRight);
            textureData.put(textureBottom);
            textureData.put(textureTop);
            textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
                * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
        
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

        shader = new Shader(gl);
        shader.attachVertexShader(gl);
        shader.attachFragmentShader(gl);
        shader.link(gl);
    }
        
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   
 

        
        shader.bind(gl);
 
        this.textureFileName = textureFileName;
        this.textureFileType = textureFileType;
        loadTexture(gl);
        texture.enable(gl);
        texture.bind(gl); 

        gl.glActiveTexture(GL.GL_TEXTURE0);
        shader.setUniform(gl, "tex", 0);
                    
       

          gl.glEnable(GL.GL_TEXTURE_2D);           
                
          gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
          gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
            
            /* Setup Position Pointer */
            gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
            
            /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
            gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
            
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawElements(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }
private String vertexShaderString =
        "#version 330 core\n"+

        "layout(location = 0) in vec2 pos;\n"+
        "layout(location = 1) in vec2 tex;\n"+

        "out vec2 texCoords;\n"+

        "void main()\n"+
        "{\n"+
            "texCoords = tex;\n"+
            "gl_Position = vec4(pos, 0.0, 1.0);\n"+
        "}";

private String fragmentShaderString = 
        "#version 330 core\n"+

        "uniform sampler2D tex;\n"+

        "in vec2 texCoords;\n"+
        "out vec4 outColor;\n"+

        "void main()\n"+
        "{\n"+
            "outColor = texture(tex, texCoords);\n"+
        "}";


    // ProgramID
    int programID;

    // Vertex Shader ID
    int vertexShaderID;

    // Fragment Shader ID
    int fragmentShaderID;

    public Shader(GL2ES2 gl) {
        programID = gl.glCreateProgram();
    }

    public void attachVertexShader(GL2ES2 gl) {
        
        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        vertexShaderID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { vertexShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(vertexShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(vertexShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! vertex shader compiled");}
        else {
            int[] logLength = new int[1];
            gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(vertexShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the vertex shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, vertexShaderID);
    }

    public void attachFragmentShader(GL2ES2 gl) {

        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        fragmentShaderID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { fragmentShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(fragmentShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(fragmentShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! fragment shader compiled");}
        else {  
            int[] logLength = new int[1];
            gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(fragmentShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the fragment shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, fragmentShaderID);
        
    }



public void link(GL2ES2 gl) {
    
    //link
    gl.glLinkProgram(programID);
    
    
    //check for errors
    int[] compiled = new int[1];
    gl.glGetProgramiv(programID, GL2ES2.GL_LINK_STATUS, compiled,0);
    if(compiled[0]!=0){System.out.println("Horray! Shader program linked!");}
    else {
        int[] logLength = new int[1];
        gl.glGetProgramiv(programID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

        byte[] log = new byte[logLength[0]];
        gl.glGetProgramInfoLog(programID, logLength[0], (int[])null, 0, log, 0);

        System.err.println("Error linking the program: " + new String(log));
 

          System.exit(1);
        }

/**
 * Sets the uniforms in this shader
 * 
 * @param name    The name of the uniform
 * @param values  The values of the uniforms (Max 4)
 */
public void setUniform(GL2ES2 gl, String name, float... values)
{
    if (values.length > 4)
    {
        System.err.println("Uniforms cannot have more than 4 values");
        System.exit(1);
    }
    
    // Get the location of the uniform
    int location = gl.glGetUniformLocation(programID, name);
    
    // Set the uniform values
    switch (values.length)
    {
        case 1:
            gl.glUniform1f(location, values[0]);
            break;                
        case 2:
            gl.glUniform2f(location, values[0], values[1]);
            break;                
        case 3:
            gl.glUniform3f(location, values[0], values[1], values[2]);
            break;                
        case 4:
            gl.glUniform4f(location, values[0], values[1], values[2], values[3]);
            break;
    }
}
changed shaders
Source Link

EDIT: I updated/replaced my shaders to fit the right version. The program compiles and links, but it shuts down java in drawCubeVBO().

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        float[] vertexArray = {
                 0, 0, 0,
                
                -x, x, x,
                 x, x, x,
                -x,-x, x, 
                 x,-x, x,
                 
                -x, x,-x,
                 x, x,-x,
                -x,-x,-x, 
                 x,-x,-x,
                 
        };
        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        4, 8, 7,
        4, 7, 3,
    };
    indices = Buffers.newDirectShortBuffer(indexArray.length);
    indices.put(indexArray);
    indices.flip();
    
    FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
        textureData.put(textureLeft);
        textureData.put(textureRighttextureLeft);
        textureData.put(textureBottom);
        textureData.put(textureTop);
        textureData.flip();

    int[] temp = new int[3];
    gl.glGenBuffers(3, temp, 0);

    VBOVertices = temp[0];
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
            * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

    VBOIndices = temp[1];
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndicestextureRight);
    gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
            * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
    gltextureData.glBindBufferput(GL.GL_ELEMENT_ARRAY_BUFFER, 0textureBottom);
    
     vboTextureCoordHandle = temp[2];
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
    gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

    shader = new Shaderput(gltextureTop);
    shader.attachVertexShader(gl);
    shader.attachFragmentShader(gl);
    shadertextureData.linkflip(gl);
}

public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
    shader.bind(gl);int[] temp = new int[3];
    
     gl.glEnableglGenBuffers(GL.GL_TEXTURE_2D);         3, temp, 0);

    //I'm not sure if this belongsVBOVertices in= thistemp[0];
 method or in initVBO
    thisgl.textureFileName =glBindBuffer(GL.GL_ARRAY_BUFFER, textureFileName;VBOVertices);
    this.textureFileType = textureFileType;
   gl.glBufferData(GL.GL_ARRAY_BUFFER, loadTexturevertices.capacity(gl);
    texture.enable(gl);
    texture        * Buffers.bind(glSIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glEnableClientStateglBindBuffer(GL2GL.GL_VERTEX_ARRAYGL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glEnableClientStateglBufferData(GL2GL.GL_TEXTURE_COORD_ARRAYGL_ELEMENT_ARRAY_BUFFER, indices.capacity();
    
     /* Setup Position Pointer */
    gl.glBindBuffer * Buffers.SIZEOF_SHORT, indices, (GL.GL_ARRAY_BUFFER, VBOVerticesGL_STATIC_DRAW);
        gl.glVertexPointer glBindBuffer(3, GL.GL_FLOAT, 0GL_ELEMENT_ARRAY_BUFFER, 0);
    
     /* Setup Texture 
 Coordinate Pointer */
    gl.glBindBuffer vboTextureCoordHandle = temp[2];
   (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
    gl.glTexCoordPointer glBindBuffer(2, GL.GL_FLOAT, 0GL_ELEMENT_ARRAY_BUFFER, 0vboTextureCoordHandle);
    
     gl.glBindBufferglBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
    gl.glDrawElements(GL.GL_TRIANGLESvboTextureCoordHandle, indices.capacity()textureData, GL.GL_UNSIGNED_SHORT, 0GL_STATIC_DRAW);
    
     gl.glDisableClientStateglBindBuffer(GL2GL.GL_TEXTURE_COORD_ARRAY);
   GL_ELEMENT_ARRAY_BUFFER, gl.glDisableClientState(GL2.GL_VERTEX_ARRAY0);

        shader = new Shader(gl);
        shader.unbindattachVertexShader(gl);
        shader.attachFragmentShader(gl);
        shader.link(gl);
    }

public void loadTexture(GL2 gl) {
            // Load 
 texture from image
     public void drawCubeVBO(GL2 gl, String textureFileName, String trytextureFileType) {
                // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                //I'm Usenot URLsure soif thatthis canbelongs readin fromthis JARmethod andor diskin file.initVBO
                texturethis.textureFileName = TextureIO.newTexture(getClass().getClassLoader()textureFileName;
                        this.getResource(textureFileName), // relative totextureFileType project= roottextureFileType;
                        false, textureFileTypeloadTexture(gl);
    
                // Use linear filter for texture if image is larger than the
                // original texture
                gl.glTexParameterienable(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEARgl);
                // Use linear filter for texture if image is smaller than the
                // original texture
                gl.glTexParameteribind(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEARgl);
    
                // Texture image flips vertically. Shall use TextureCoords class to
                // retrieve
                // the top,shader.bind(gl); bottom, left and right coordinates, instead of using
                // 0.0f and 1gl.0fglEnable(GL.
        GL_TEXTURE_2D);        TextureCoords textureCoords = texture.getImageTexCoords();
                
                textureTop = textureCoords.top();
                textureBottom = textureCoordsgl.bottomglEnableClientState();
                textureLeft = textureCoordsGL2.left(GL_VERTEX_ARRAY);
                textureRight = textureCoordsgl.right();glEnableClientState
    
    (GL2.GL_TEXTURE_COORD_ARRAY);
        } catch (GLException e) {
            /* Setup Position Pointer */
 e           gl.printStackTraceglBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
            } 
 catch           /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (IOExceptionGL.GL_ARRAY_BUFFER, evboTextureCoordHandle);
 {           gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
             
    e        gl.printStackTraceglBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            }gl.glDrawEleme

nts(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }
    private String vertexShaderString =
            "#version 110\n"+330\n"+
             
        "void main   "layout (std140) uniform Matrices {\n"+
                "mat4 m_pvm;\n"+
                "mat4 m_viewModel;\n"+
                "mat3 m_normal;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
            "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix"vec3 *l_dir;\n"+ gl_Vertex;\n"+   // camera space
            "gl_TexCoord[0]"};\n"+
 = gl_MultiTexCoord0;\n"+           
            "in vec4 position;\n"+   // local space
            "in vec3 normal;\n"+     // local space
            "in vec2 texCoord;\n"+
             
            // the data to be sent to the fragment shader
            "out Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "}"; DataOut;\n"+
             
private String fragmentShaderString          "void main () {\n"+
             
                "DataOut.normal = normalize(m_normal * normal);\n"+
        "#version 110 core\n" +     "DataOut.eye = -(m_viewModel * position);\n"+
                "DataOut.texCoord = texCoord;\n"+
        "uniform sampler2D color_texture;\n" +  
                "gl_Position = m_pvm * position;\n"+
            "}";

    private String fragmentShaderString = 
            "#version 330\n"+
             
            "layout (std140) uniform Material {\n"+
                "vec4 diffuse;\n"+
                "vec4 ambient;\n"+
                "vec4 specular;\n"+
                "float shininess;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataIn;\n"+
             
            "uniform sampler2D texUnit;\n"+
             
            "out vec4 colorOut;\n"+
             
            "void main() {\n"\n"+
 +            
            "gl_FragColor    // set the specular term to black
                "vec4 spec = texture2Dvec4(color_texture0.0);\n"+
             
                // normalize both input vectors
                "vec3 n = normalize(DataIn.normal);\n"+
                "vec3 e = normalize(vec3(DataIn.eye));\n"+
             
                "float intensity = max(dot(n,l_dir), gl_TexCoord[0]0.st0);;\n";\n"+
             
                // if the vertex is lit compute the specular color
                "if (intensity > 0.0) {\n"+
                    // compute the half vector
                    "vec3 h = normalize(l_dir + e);\n"+
                    // compute the specular term into spec
                    "float intSpec = max(dot(h,n), 0.0);\n"+
                    "spec = specular * pow(intSpec,shininess);\n"+
                "}\n"+
                "vec4 texColor = texture(texUnit, DataIn.texCoord);\n"+
                "vec4 diffColor = intensity *  diffuse * texColor;\n"+
                "vec4 ambColor = ambient * texColor;\n"+
             
                "colorOut = max(diffColor + spec, ambColor);\n"+
            "}";


    // ProgramID
    int programID;

    // Vertex Shader ID
    int vertexShaderID;

    // Fragment Shader ID
    int fragmentShaderID;

    public Shader(GL2ES2 gl) {
        programID = gl.glCreateProgram();
    }

    public void attachVertexShader(GL2ES2 gl) {
        
        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        vertexShaderID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { vertexShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(vertexShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(vertexShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! vertex shader compiled");}
        else {
            int[] logLength = new int[1];
            gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(vertexShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the vertex shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, vertexShaderID);
    }
    
    //Attach Shader
    gl.glAttachShader(programID, vertexShaderID);
}

    public void attachFragmentShader(GL2ES2 gl) {

        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        fragmentShaderID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { fragmentShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(fragmentShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(fragmentShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! fragment shader compiled");}
        else {  
            int[] logLength = new int[1];
            gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(fragmentShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the fragment shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, fragmentShaderID);
        
    }
    
    //Attach Shader
    gl.glAttachShader(programID, fragmentShaderID);
    
}

public void link(GL2ES2 gl) {
    
    //link
    gl.glLinkProgram(programID);
    
    
    public void link(GL2ES2 gl) {
        
        //link
        gl.glLinkProgram(programID);
        
        
        //check for errors
        int[] compiled = new int[1];
        gl.glGetProgramiv(programID, GL2ES2.GL_LINK_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! Shader program linked!");}
        else {
            int[] logLength = new int[1];
            gl.glGetProgramiv(programID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetProgramInfoLog(programID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error linking the program: " + new String(log));
            System.exit(1);
        }
public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

    float[] vertexArray = {
             0, 0, 0,
            
            -x, x, x,
             x, x, x,
            -x,-x, x, 
             x,-x, x,
             
            -x, x,-x,
             x, x,-x,
            -x,-x,-x, 
             x,-x,-x,
             
    };
    vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
    vertices.put(vertexArray);
    vertices.flip();

    short[] indexArray = {
        1, 2, 4,
        1, 4, 3, 
        
        1, 7, 5,
        1, 3, 7,
        
        1, 5, 2, 
        5, 6, 2, 
        
        7, 8, 5,
        5, 8, 6,
        
        2, 6, 8,
        2, 8, 4,
        
        4, 8, 7,
        4, 7, 3,
    };
    indices = Buffers.newDirectShortBuffer(indexArray.length);
    indices.put(indexArray);
    indices.flip();
    
    FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
        textureData.put(textureLeft);
        textureData.put(textureRight);
        textureData.put(textureBottom);
        textureData.put(textureTop);
        textureData.flip();

    int[] temp = new int[3];
    gl.glGenBuffers(3, temp, 0);

    VBOVertices = temp[0];
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
            * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

    VBOIndices = temp[1];
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
    gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
            * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
    
     vboTextureCoordHandle = temp[2];
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
    gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

    shader = new Shader(gl);
    shader.attachVertexShader(gl);
    shader.attachFragmentShader(gl);
    shader.link(gl);
}

public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
    shader.bind(gl);        
     gl.glEnable(GL.GL_TEXTURE_2D);           

    //I'm not sure if this belongs in this method or in initVBO
    this.textureFileName = textureFileName;
    this.textureFileType = textureFileType;
    loadTexture(gl);
    texture.enable(gl);
    texture.bind(gl);
    

    
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
    
     /* Setup Position Pointer */
    gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
    gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
    
     /* Setup Texture Coordinate Pointer */
    gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
    gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
    
     gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
    gl.glDrawElements(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
    
     gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

    shader.unbind(gl);
       
    }

public void loadTexture(GL2 gl) {
            // Load texture from image
            try {
                // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                // Use URL so that can read from JAR and disk file.
                texture = TextureIO.newTexture(getClass().getClassLoader()
                        .getResource(textureFileName), // relative to project root
                        false, textureFileType);
    
                // Use linear filter for texture if image is larger than the
                // original texture
                gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                // Use linear filter for texture if image is smaller than the
                // original texture
                gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
                // Texture image flips vertically. Shall use TextureCoords class to
                // retrieve
                // the top, bottom, left and right coordinates, instead of using
                // 0.0f and 1.0f.
                TextureCoords textureCoords = texture.getImageTexCoords();
                
                textureTop = textureCoords.top();
                textureBottom = textureCoords.bottom();
                textureLeft = textureCoords.left();
                textureRight = textureCoords.right();
    
            } catch (GLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

    }
    private String vertexShaderString =
        "#version 110\n"+

        "void main()\n"+
        "{\n"+
            "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n"+
            "gl_TexCoord[0] = gl_MultiTexCoord0;\n"+
        "}";

private String fragmentShaderString = 
        "#version 110 core\n" +

        "uniform sampler2D color_texture;\n" +

        "void main() {\n" +
            "gl_FragColor = texture2D(color_texture, gl_TexCoord[0].st);;\n" + 
        "} ";


// ProgramID
int programID;

// Vertex Shader ID
int vertexShaderID;

// Fragment Shader ID
int fragmentShaderID;

public Shader(GL2ES2 gl) {
    programID = gl.glCreateProgram();
}

public void attachVertexShader(GL2ES2 gl) {
    
    // Create GPU shader handles
    // OpenGL ES retuns a index id to be stored for future reference.
    vertexShaderID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
    
    // Load and compile the source
    String[] vlines = new String[] { vertexShaderString };
    int[] vlengths = new int[] { vlines[0].length() };
    gl.glShaderSource(vertexShaderID, vlines.length, vlines, vlengths, 0);
    gl.glCompileShader(vertexShaderID);
    
    //Check compile status for errors
    int[] compiled = new int[1];
    gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
    if(compiled[0]!=0){System.out.println("Horray! vertex shader compiled");}
    else {
        int[] logLength = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

        byte[] log = new byte[logLength[0]];
        gl.glGetShaderInfoLog(vertexShaderID, logLength[0], (int[])null, 0, log, 0);

        System.err.println("Error compiling the vertex shader: " + new String(log));
        System.exit(1);
    }
    
    //Attach Shader
    gl.glAttachShader(programID, vertexShaderID);
}

public void attachFragmentShader(GL2ES2 gl) {

    // Create GPU shader handles
    // OpenGL ES retuns a index id to be stored for future reference.
    fragmentShaderID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
    
    // Load and compile the source
    String[] vlines = new String[] { fragmentShaderString };
    int[] vlengths = new int[] { vlines[0].length() };
    gl.glShaderSource(fragmentShaderID, vlines.length, vlines, vlengths, 0);
    gl.glCompileShader(fragmentShaderID);
    
    //Check compile status for errors
    int[] compiled = new int[1];
    gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
    if(compiled[0]!=0){System.out.println("Horray! fragment shader compiled");}
    else {  
        int[] logLength = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

        byte[] log = new byte[logLength[0]];
        gl.glGetShaderInfoLog(fragmentShaderID, logLength[0], (int[])null, 0, log, 0);

        System.err.println("Error compiling the fragment shader: " + new String(log));
        System.exit(1);
    }
    
    //Attach Shader
    gl.glAttachShader(programID, fragmentShaderID);
    
}

public void link(GL2ES2 gl) {
    
    //link
    gl.glLinkProgram(programID);
    
    
    //check for errors
    int[] compiled = new int[1];
    gl.glGetProgramiv(programID, GL2ES2.GL_LINK_STATUS, compiled,0);
    if(compiled[0]!=0){System.out.println("Horray! Shader program linked!");}
    else {
        int[] logLength = new int[1];
        gl.glGetProgramiv(programID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

        byte[] log = new byte[logLength[0]];
        gl.glGetProgramInfoLog(programID, logLength[0], (int[])null, 0, log, 0);

        System.err.println("Error linking the program: " + new String(log));
        System.exit(1);
    }

EDIT: I updated/replaced my shaders to fit the right version. The program compiles and links, but it shuts down java in drawCubeVBO().

    public void initVBO(GL2 gl, String textureFileName, String textureFileType) {

        float[] vertexArray = {
                 0, 0, 0,
                
                -x, x, x,
                 x, x, x,
                -x,-x, x, 
                 x,-x, x,
                 
                -x, x,-x,
                 x, x,-x,
                -x,-x,-x, 
                 x,-x,-x,
                 
        };
        vertices = Buffers.newDirectFloatBuffer(vertexArray.length);
        vertices.put(vertexArray);
        vertices.flip();

        short[] indexArray = {
            1, 2, 4,
            1, 4, 3, 
            
            1, 7, 5,
            1, 3, 7,
            
            1, 5, 2, 
            5, 6, 2, 
            
            7, 8, 5,
            5, 8, 6,
            
            2, 6, 8,
            2, 8, 4,
            
            4, 8, 7,
            4, 7, 3,
        };
        indices = Buffers.newDirectShortBuffer(indexArray.length);
        indices.put(indexArray);
        indices.flip();
        
        FloatBuffer textureData = Buffers.newDirectFloatBuffer(12);
            textureData.put(textureLeft);
            textureData.put(textureRight);
            textureData.put(textureBottom);
            textureData.put(textureTop);
            textureData.flip();

        int[] temp = new int[3];
        gl.glGenBuffers(3, temp, 0);

        VBOVertices = temp[0];
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity()
                * Buffers.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);

        VBOIndices = temp[1];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity()
                * Buffers.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
         
        vboTextureCoordHandle = temp[2];
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle);
        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vboTextureCoordHandle, textureData, GL.GL_STATIC_DRAW);
        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);

        shader = new Shader(gl);
        shader.attachVertexShader(gl);
        shader.attachFragmentShader(gl);
        shader.link(gl);
    }
         
        public void drawCubeVBO(GL2 gl, String textureFileName, String textureFileType) {
                   
     //I'm not sure if this belongs in this method or in initVBO
            this.textureFileName = textureFileName;
            this.textureFileType = textureFileType;
            loadTexture(gl);
            texture.enable(gl);
                texture.bind(gl);
        
        shader.bind(gl);        
                gl.glEnable(GL.GL_TEXTURE_2D);           
                
                gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
                gl.glEnableClientState
    
    (GL2.GL_TEXTURE_COORD_ARRAY);
            
            /* Setup Position Pointer */
            gl.glBindBuffer    (GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer (3, GL.GL_FLOAT, 0, 0);
             
            /* Setup Texture Coordinate Pointer */
            gl.glBindBuffer      (GL.GL_ARRAY_BUFFER, vboTextureCoordHandle);
            gl.glTexCoordPointer (2, GL.GL_FLOAT, 0, 0);
             
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawEleme

nts(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
        
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
 
        shader.unbind(gl);
           
        }
    
    public void loadTexture(GL2 gl) {
                // Load texture from image
                try {
                    // Create a OpenGL Texture object from (URL, mipmap, file suffix)
                    // Use URL so that can read from JAR and disk file.
                    texture = TextureIO.newTexture(getClass().getClassLoader()
                            .getResource(textureFileName), // relative to project root
                            false, textureFileType);
        
                    // Use linear filter for texture if image is larger than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // Use linear filter for texture if image is smaller than the
                    // original texture
                    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
                    // Texture image flips vertically. Shall use TextureCoords class to
                    // retrieve
                    // the top, bottom, left and right coordinates, instead of using
                    // 0.0f and 1.0f.
                    TextureCoords textureCoords = texture.getImageTexCoords();
                    
                    textureTop = textureCoords.top();
                    textureBottom = textureCoords.bottom();
                    textureLeft = textureCoords.left();
                    textureRight = textureCoords.right();
        
                } catch (GLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
        }
private String vertexShaderString =
            "#version 330\n"+
             
            "layout (std140) uniform Matrices {\n"+
                "mat4 m_pvm;\n"+
                "mat4 m_viewModel;\n"+
                "mat3 m_normal;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in vec4 position;\n"+   // local space
            "in vec3 normal;\n"+     // local space
            "in vec2 texCoord;\n"+
             
            // the data to be sent to the fragment shader
            "out Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataOut;\n"+
             
            "void main () {\n"+
             
                "DataOut.normal = normalize(m_normal * normal);\n"+
                "DataOut.eye = -(m_viewModel * position);\n"+
                "DataOut.texCoord = texCoord;\n"+
             
                "gl_Position = m_pvm * position;\n"+
            "}";

    private String fragmentShaderString = 
            "#version 330\n"+
             
            "layout (std140) uniform Material {\n"+
                "vec4 diffuse;\n"+
                "vec4 ambient;\n"+
                "vec4 specular;\n"+
                "float shininess;\n"+
            "};\n"+
             
            "layout (std140) uniform Lights {\n"+
                "vec3 l_dir;\n"+    // camera space
            "};\n"+
             
            "in Data {\n"+
                "vec3 normal;\n"+
                "vec4 eye;\n"+
                "vec2 texCoord;\n"+
            "} DataIn;\n"+
             
            "uniform sampler2D texUnit;\n"+
             
            "out vec4 colorOut;\n"+
             
            "void main() {\n"+
             
                // set the specular term to black
                "vec4 spec = vec4(0.0);\n"+
             
                // normalize both input vectors
                "vec3 n = normalize(DataIn.normal);\n"+
                "vec3 e = normalize(vec3(DataIn.eye));\n"+
             
                "float intensity = max(dot(n,l_dir), 0.0);\n"+
             
                // if the vertex is lit compute the specular color
                "if (intensity > 0.0) {\n"+
                    // compute the half vector
                    "vec3 h = normalize(l_dir + e);\n"+
                    // compute the specular term into spec
                    "float intSpec = max(dot(h,n), 0.0);\n"+
                    "spec = specular * pow(intSpec,shininess);\n"+
                "}\n"+
                "vec4 texColor = texture(texUnit, DataIn.texCoord);\n"+
                "vec4 diffColor = intensity *  diffuse * texColor;\n"+
                "vec4 ambColor = ambient * texColor;\n"+
             
                "colorOut = max(diffColor + spec, ambColor);\n"+
            "}";


    // ProgramID
    int programID;

    // Vertex Shader ID
    int vertexShaderID;

    // Fragment Shader ID
    int fragmentShaderID;

    public Shader(GL2ES2 gl) {
        programID = gl.glCreateProgram();
    }

    public void attachVertexShader(GL2ES2 gl) {
        
        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        vertexShaderID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { vertexShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(vertexShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(vertexShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! vertex shader compiled");}
        else {
            int[] logLength = new int[1];
            gl.glGetShaderiv(vertexShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(vertexShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the vertex shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, vertexShaderID);
    }

    public void attachFragmentShader(GL2ES2 gl) {

        // Create GPU shader handles
        // OpenGL ES retuns a index id to be stored for future reference.
        fragmentShaderID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
        
        // Load and compile the source
        String[] vlines = new String[] { fragmentShaderString };
        int[] vlengths = new int[] { vlines[0].length() };
        gl.glShaderSource(fragmentShaderID, vlines.length, vlines, vlengths, 0);
        gl.glCompileShader(fragmentShaderID);
        
        //Check compile status for errors
        int[] compiled = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! fragment shader compiled");}
        else {  
            int[] logLength = new int[1];
            gl.glGetShaderiv(fragmentShaderID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetShaderInfoLog(fragmentShaderID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error compiling the fragment shader: " + new String(log));
            System.exit(1);
        }
        
        //Attach Shader
        gl.glAttachShader(programID, fragmentShaderID);
        
    }
    
    public void link(GL2ES2 gl) {
        
        //link
        gl.glLinkProgram(programID);
        
        
        //check for errors
        int[] compiled = new int[1];
        gl.glGetProgramiv(programID, GL2ES2.GL_LINK_STATUS, compiled,0);
        if(compiled[0]!=0){System.out.println("Horray! Shader program linked!");}
        else {
            int[] logLength = new int[1];
            gl.glGetProgramiv(programID, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);

            byte[] log = new byte[logLength[0]];
            gl.glGetProgramInfoLog(programID, logLength[0], (int[])null, 0, log, 0);

            System.err.println("Error linking the program: " + new String(log));
            System.exit(1);
        }
added shaders
Source Link
Loading
Source Link
Loading