Skip to main content
added 230 characters in body
Source Link
remi
  • 1.1k
  • 4
  • 21
  • 50

UPDATE I

I no longer get the above error after fixing a mistake. I now get a complain after glCompileShader():

I doubt more of the code is needed to find the problem here, but just let me know. Thanks a lot in advance!

SOLUTION

The first answer below did the trick. I removed:

layout (location = 0) 

from the vertex shader and then added:

glBindAttribLocation(ShaderProgram, 0, "Position"); 

before the linking.

UPDATE I no longer get the above error after fixing a mistake. I now get a complain after glCompileShader():

I doubt more of the code is needed to find the problem here, but just let me know. Thanks a lot in advance!

UPDATE

I no longer get the above error after fixing a mistake. I now get a complain after glCompileShader():

I doubt more of the code is needed to find the problem here, but just let me know. Thanks a lot in advance!

SOLUTION

The first answer below did the trick. I removed:

layout (location = 0) 

from the vertex shader and then added:

glBindAttribLocation(ShaderProgram, 0, "Position"); 

before the linking.

added 824 characters in body
Source Link
remi
  • 1.1k
  • 4
  • 21
  • 50

I assumeUPDATE I no longer get the above error originates in one of the following functionsafter fixing a mistake. I now get a complain after glCompileShader():

"Error: 0:3 'location' : syntax error parse error"

So I imagine it has to do with my shader files (will add them below). The shader files are taken from a tutorial, so I assumed they would work.

Shader files:

Vertex shader:

#version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5*Position.x, 0.5*Position.y, Position.z, 1.0); } 

Fragment shader:

#version 330 out vec4 FragColor; void main() { FragColor = vec4(1.0, 0.0, 0.0, 1.0); } 
static void AddShader(GLuint ShaderProgram, GLenum ShaderType, std::string filePath){ //create shader object GLuint ShaderObj = glCreateShader(ShaderType); //error if no shader if (ShaderObj === 0){ fprintf(stderr, "Error creating shader type %d\n", ShaderType); exit(0); } //"specify source code" //readShaderFile returns the shader file as a string std::string shaderFile = readShaderFile(filePath); const char* shaderFilePointer = shaderFile.c_str(); GLint ShaderFileLength[1]; ShaderFileLength[0] = strlen(shaderFilePointer); glShaderSource(ShaderObj, 1, &shaderFilePointer, ShaderFileLength); //compile the shader glCompileShader(ShaderObj); //check if compile successful GLint success; glGetShaderiv(ShaderObj, GL_COMPILE_STATUS, &success); if (!success){ GLchar InfoLog[1024]; glGetShaderInfoLog(ShaderObj, sizeof(InfoLog), NULL, InfoLog); fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog); exit(1); } glAttachShader(ShaderProgram, ShaderObj); } 

I assume the error originates in one of the following functions:

static void AddShader(GLuint ShaderProgram, GLenum ShaderType, std::string filePath){ //create shader object GLuint ShaderObj = glCreateShader(ShaderType); //error if no shader if (ShaderObj = 0){ fprintf(stderr, "Error creating shader type %d\n", ShaderType); exit(0); } //"specify source code" //readShaderFile returns the shader file as a string std::string shaderFile = readShaderFile(filePath); const char* shaderFilePointer = shaderFile.c_str(); GLint ShaderFileLength[1]; ShaderFileLength[0] = strlen(shaderFilePointer); glShaderSource(ShaderObj, 1, &shaderFilePointer, ShaderFileLength); //compile the shader glCompileShader(ShaderObj); //check if compile successful GLint success; glGetShaderiv(ShaderObj, GL_COMPILE_STATUS, &success); if (!success){ GLchar InfoLog[1024]; glGetShaderInfoLog(ShaderObj, sizeof(InfoLog), NULL, InfoLog); fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog); exit(1); } glAttachShader(ShaderProgram, ShaderObj); } 

UPDATE I no longer get the above error after fixing a mistake. I now get a complain after glCompileShader():

"Error: 0:3 'location' : syntax error parse error"

So I imagine it has to do with my shader files (will add them below). The shader files are taken from a tutorial, so I assumed they would work.

Shader files:

Vertex shader:

#version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5*Position.x, 0.5*Position.y, Position.z, 1.0); } 

Fragment shader:

#version 330 out vec4 FragColor; void main() { FragColor = vec4(1.0, 0.0, 0.0, 1.0); } 
static void AddShader(GLuint ShaderProgram, GLenum ShaderType, std::string filePath){ //create shader object GLuint ShaderObj = glCreateShader(ShaderType); //error if no shader if (ShaderObj == 0){ fprintf(stderr, "Error creating shader type %d\n", ShaderType); exit(0); } //"specify source code" //readShaderFile returns the shader file as a string std::string shaderFile = readShaderFile(filePath); const char* shaderFilePointer = shaderFile.c_str(); GLint ShaderFileLength[1]; ShaderFileLength[0] = strlen(shaderFilePointer); glShaderSource(ShaderObj, 1, &shaderFilePointer, ShaderFileLength); //compile the shader glCompileShader(ShaderObj); //check if compile successful GLint success; glGetShaderiv(ShaderObj, GL_COMPILE_STATUS, &success); if (!success){ GLchar InfoLog[1024]; glGetShaderInfoLog(ShaderObj, sizeof(InfoLog), NULL, InfoLog); fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog); exit(1); } glAttachShader(ShaderProgram, ShaderObj); } 
added 91 characters in body
Source Link
remi
  • 1.1k
  • 4
  • 21
  • 50

I get an error when linking the shaders (I suspect the error can be tracked down to the compiling of the shader though). I know my shaders are read by my program, but any changes to them doesn't affect my error. By running:

I get an error when linking the shaders (I suspect the error can be tracked down to the compiling of the shader though). By running:

I get an error when linking the shaders (I suspect the error can be tracked down to the compiling of the shader though). I know my shaders are read by my program, but any changes to them doesn't affect my error. By running:

Source Link
remi
  • 1.1k
  • 4
  • 21
  • 50
Loading