I'm making a game engine right now, and I'm at the point of creating my first graphical object, though I'm encountering an error: when I run my program, the process of creating a shader program in open gl gives me this error:
error C5145: must write to gl_Position
Don't get me wrong on that: I found some stuff here and on other websites about the same problem, though the solutions don't work for me. They say I should write
glShaderSource(vertexShader, 1, &src, NULL);
instead of
glShaderSource(GL_VERTEX_SHADER, 1, &src, NULL);
(giving the method the, by me declared, unsigned int vertexShader instead of the by opengl defined macro GL_VERTEX_SHADER) but I still encounter the problem when writing it the "correct" way.
Here's my code for creating the shaders and linking the shader program:
vertex shader:
char* src = readShaderFile(path);
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &src, NULL);
glCompileShader(vertexShader);
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if(!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << endl;
}
else
cout << "vertex shader compiled" << endl;
fragment shader:
char* src = readShaderFile(path);
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &src, NULL);
glCompileShader(fragmentShader);
int success;
char infoLog[512];
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if(!success)
{
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << endl;
}
else
cout << "fragment shader compiled" << endl;
and shader program:
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
int success;
char infoLog[512];
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
cout << "ERROR::SHADER::PROGRAM::LINKING::FAILED\n" << infoLog << endl;
}
else
cout << "shader program created" << endl;
the variables "vertexShader", "fragmentShader" and "shaderProgram" are unsigned ints
Note that the vertex shader and the fragment shader seem to compile just fine, since it doesn't "fail"