This is the part of the source code where the problem resides:
GL.createCapabilities();
// Define the viewport dimensions
glViewport(0, 0, 300, 300);
int shaderProgram;
final String vertexShader = "#version 330 core\n in vec3 position; // The position variable has attribute position 0\n out vec4 vertexColor; // Specify a color output to the fragment shader\n void main()\n {\n gl_Position = vec4(position, 1.0); // See how we directly give a vec3 to vec4's constructor\n vertexColor = vec4(0.5f, 0.0f, 0.0f, 1.0f); // Set the output variable to a dark-red color\n }";
String fragmentShader = "#version 330 core\n in vec3 ourColor;\n"
+ "in vec2 TexCoord;\n"
+ "out vec4 color;\n"
+ "uniform sampler2D ourTexture1;\n"
+ "void main()\n"
+ "{\n"
+ "color = vec4(ourColor, 1.0f);\n"
+ "}";
int vertex, fragment;
// Vertex Shader
vertex = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
GL20.glShaderSource(vertex, vertexShader);
GL20.glCompileShader(vertex);
// Fragment Shader
fragment = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
GL20.glShaderSource(fragment, fragmentShader);
GL20.glCompileShader(fragment);
//create program and bind shaders to program
shaderProgram = GL20.glCreateProgram();
GL20.glAttachShader(shaderProgram, vertex);
GL20.glAttachShader(shaderProgram, fragment);
GL20.glLinkProgram(shaderProgram);
int vlength = GL20.GL_SHADER_SOURCE_LENGTH;
int iscompiled = GL20.glGetProgrami(fragment, GL20.GL_COMPILE_STATUS);
if(iscompiled == GL_FALSE)
{
System.out.println(glGetString(GL_VERSION));
System.out.println("not compiled");
System.out.println(GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
System.out.println(GL20.glGetShaderInfoLog(vertex));
return;
}
int isLinked = GL20.glGetProgrami(shaderProgram, GL20.GL_LINK_STATUS);
if(isLinked == GL_FALSE)
{
System.out.println("failed linking");
return;
}
This is the vertex shader:
#version 330 core
layout (location = 0) in vec3 position; // The position variable has attribute position 0
out vec4 vertexColor; // Specify a color output to the fragment shader
void main()
{
gl_Position = vec4(position, 1.0); // See how we directly give a vec3 to vec4's constructor
vertexColor = vec4(0.5f, 0.0f, 0.0f, 1.0f); // Set the output variable to a dark-red color
}
This is the fragment shader:
#version 330 core
in vec4 vertexColor; // The input variable from the vertex shader (same name and same type)
out vec4 color;
void main()
{
color = vertexColor;
}
Both of the shaders don't compile. Niether the vertex or fragment shader. What needs to be fixed? I am using the core profile of opengl version 3.3. The operating system being run is windows vista home premium 64 bit.
int iscompiled = GL20.glGetProgrami(fragment, GL20.GL_COMPILE_STATUS);
You cannot query a program for compilation status. That is a property of each shader object seperately, and can be queried via glGetShaderiv()
. Using GL_COMPILE_STATUS
for glGetProgramiv()
will just result in an GL_INVALID_ENUM
error.