I've been trying to get shaders to work. They don't.
std::cout << "a " << glGetError() <<std::endl; //making sure things work
GLuint vertexShader = 0;
GLuint fragmentShader = 1;
glCreateShader(GL_VERTEX_SHADER);
std::cout <<"b " << glGetError() <<std::endl;
glCreateShader(GL_FRAGMENT_SHADER);
std::cout <<"c " << glGetError() <<std::endl;
glShaderSource(vertexShader, GLsizei(1), (const char**)&VertexShaderSource, NULL);//ERROR
std::cout <<"d " << glGetError() <<std::endl;
glShaderSource(fragmentShader, GLsizei(1), (const char**)&FragmentShaderSource, NULL);//is somehow fine
std::cout <<"e " << glGetError() <<std::endl;
glCompileShader(vertexShader);
std::cout <<"f " << glGetError() <<std::endl;
glCompileShader(fragmentShader);
std::cout <<"g " << glGetError() <<std::endl;'
Now, the output is:
a 0
b 0
c 0
d 1281
e 0
f 1281
g 0
This means that the first glShaderSource
call is not working, but, for some reason the next glShaderSource
works, while doing what I think is the exactly same thing.
What is going on in here???
Shaders are:
const std::string VertexShaderSource ="#version 330 core"
""
"layout (location = 0) in vec3 position;"
""
"void main()"
"{"
" gl_Position = vec4(position.x, position.y, position.z, 1.0);"
"}";
const std::string FragmentShaderSource ="#version 330 core"
""
"out vec4 color;"
""
"void main()"
"{"
" color = vec4(1.0f, 1.0f, 1.0f, 1.0f);"
"}";
And if passing string this way ((const char**)&VertexShaderSource)
is wrong, then why the second call works just fine?