I left the OpenGL world about twenty years ago and now with plenty of timeon my hands, I’m back. Following the excellent guidance of “Learn OpenGL” at LearnOpenGL - Shaders, I’m stuck at the very first example of linking vertex shaders to fragment shaders. The error is ERROR: 0:4: '{' : syntax error: syntax error
. the offending code is
// Vertex shader
const char* vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"out vec4 vertexColor;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
" vertexColor = vec4(0.5, 0.0, 0.0, 1.0);\n"
"}\0";
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
int success;
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
// declare infoLog here since it's used in two blocks below
char infoLog[512];
if(!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
fputs(infoLog, stderr);
}
// Fragment shader
const char* fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"in vec4 vertexColor;\n"
"void main()\n"
"{\n"
" FragColor = vertexColor;\n"
"}\0";
unsigned int fragmentShader;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if(!success)
I’m pretty sure the issue will be obvious to someone more experienced than I in OpenGL, but I’ve looked at it until I’m bleary-eyed and can’t fathom what’s wrong. Any help will be appreciated