No, I haven't checked any of that. LWJGL seems to handle errors pretty well, it gives pretty good feedback if it doesn't like something.
I'm using Oskar @ thecodinguniverse.com's method for creating the shader program. My only modifications are passing the filename to another method, that returns the entire contents of the text back as a string for compilation. It seems to do what it's supposed to do, I didn't see a reason to reinvent the wheel.
public static int loadShaderPair(String vertexShaderName, String fragmentShaderName) throws IOException{
int shaderProgram = glCreateProgram();
int vertexShader = glCreateShader(GL_VERTEX_SHADER);
int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vertexShader, TextToString.convertToString("res\\shaders\\" + vertexShaderName));
glCompileShader(vertexShader);
if (glGetShaderi(vertexShader, GL_COMPILE_STATUS) == GL_FALSE) {
System.err
.println("Vertex shader wasn't able to be compiled correctly. Error log:");
System.err.println(glGetShaderInfoLog(vertexShader, glGetProgrami(shaderProgram, GL_INFO_LOG_LENGTH)));
return -1;
}
glShaderSource(fragmentShader, TextToString.convertToString("res\\shaders\\" + fragmentShaderName));
glCompileShader(fragmentShader);
if (glGetShaderi(fragmentShader, GL_COMPILE_STATUS) == GL_FALSE) {
System.err
.println("Fragment shader wasn't able to be compiled correctly. Error log:");
System.err.println(glGetShaderInfoLog(fragmentShader, glGetProgrami(shaderProgram, GL_INFO_LOG_LENGTH)));
}
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
if (glGetProgrami(shaderProgram, GL_LINK_STATUS) == GL_FALSE) {
System.err.println("Shader program wasn't linked correctly.");
System.err.println(glGetProgramInfoLog(shaderProgram, 1024));
return -1;
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
return shaderProgram;
}
I'm also using his simple "pixel_phong_lighting" shaders. I have the OpenGL 4.0 Shading Language Cookbook" coming in a few days, until then I'm just using what I know will work. I'm also still using the built in matrix functions, coloring and shininess. My next step after I get this back to functioning how it should, is using my own matrix system.
Fragment Shader:
/*
* Copyright (c) 2012, Oskar Veerhoek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
#version 120
// The colour that we passed in through the vertex shader.
varying vec4 varyingColour;
// The normal that we passed in through the vertex shader.
varying vec3 varyingNormal;
// The vertex that we passed in through the vertex shader.
varying vec4 varyingVertex;
void main() {
vec3 vertexPosition = (gl_ModelViewMatrix * varyingVertex).xyz;
vec3 surfaceNormal = normalize((gl_NormalMatrix * varyingNormal).xyz);
vec3 lightDirection = normalize(gl_LightSource[0].position.xyz - vertexPosition);
float diffuseLightIntensity = max(0, dot(surfaceNormal, lightDirection));
gl_FragColor.rgb = diffuseLightIntensity * varyingColour.rgb;
gl_FragColor += gl_LightModel.ambient;
vec3 reflectionDirection = normalize(reflect(-lightDirection, surfaceNormal));
float specular = max(0.0, dot(surfaceNormal, reflectionDirection));
if (diffuseLightIntensity != 0) {
float fspecular = pow(specular, gl_FrontMaterial.shininess);
gl_FragColor += fspecular;
}
}
Vertex Shader:
/*
* Copyright (c) 2012, Oskar Veerhoek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
#version 120
// The colour we're going to pass to the fragment shader.
varying vec4 varyingColour;
// The normal we're going to pass to the fragment shader.
varying vec3 varyingNormal;
// The vertex we're going to pass to the fragment shader.
varying vec4 varyingVertex;
void main() {
// Pass the vertex colour attribute to the fragment shader.
// This value will be interpolated automatically by OpenGL
// if GL_SHADE_MODEL is GL_SMOOTH. (that's the default)
varyingColour = gl_Color;
// Pass the vertex normal attribute to the fragment shader.
// This value will be interpolated automatically by OpenGL
// if GL_SHADE_MODEL is GL_SMOOTH. (that's the default)
varyingNormal = gl_Normal;
// Pass the vertex position attribute to the fragment shader.
// This value will be interpolated automatically by OpenGL
// if GL_SHADE_MODEL is GL_SMOOTH. (that's the default)
varyingVertex = gl_Vertex;
// Send the vertex position, modified by glTranslate/glRotate/glScale
// and glOrtho/glFrustum/gluPerspective to primitive assembly.
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
and finally, my full render method
public void render() {
glPushMatrix();// deprecated
glRotatef(rotation, rx, ry, rz);// deprecated
glTranslatef(x, y, z);// deprecated
glScalef(sx, sy, sz);// deprecated
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10f); //deprecated
glColor4f(1f, 0f,0f,1f);//deprecated
glUseProgram(shaderProgram);
glDrawArrays(GL_TRIANGLES, 0, model.getFaces().size() * 9);
glUseProgram(0);
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glPopMatrix();// deprecated
}
And finally, some screenshots

