I’m having some problems getting my shader to work and I seek guidance, please.
When I run the code below, the triangles that I output is white and not the color specified in verts at the end of the second code block.
Any help is appreciated.
Also, here is the result from running GL_SHADING_LANGUAGE
Intel
Intel(R) HD Graphics Family
3.1.0 - Build 8.15.10.2476
1.40 - Intel Build 8.15.10.2476
This is my shader code.
const char* vertexShaderCode =
“#version 140
"
“”
“in layout(location=0) vec2 position;”
“in layout(location=1) vec3 vertexColor;”
“out vec3 theColor;”
“”
“void main()”
“{”
" gl_Position = vec4(position, 0.0, 1.0);”
" theColor = vertexColor;"
“}” ;const char* fragmentShaderCode =
“#version 140
"
“”
“out vec4 daColor;”
“in vec3 theColor;”
“”
“void main()”
“{”
" daColor = vec4(theColor, 1.0);”
“}”;
And here is the code that does to compiling, linking, and such
void installShaders()
{
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);const char* adapter[1];
adapter[0] = vertexShaderCode;
glShaderSource(vertexShaderID,1,adapter, NULL);
adapter[0] = fragmentShaderCode;
glShaderSource(fragmentShaderID, 1, adapter, NULL);glCompileShader(vertexShaderID);
glCompileShader(fragmentShaderID);GLuint programID = glCreateProgram();
glAttachShader(programID, vertexShaderID);
glAttachShader(programID, fragmentShaderID);glLinkProgram(programID);
glUseProgram(programID);
std::cout << fragmentShaderCode << std::endl;
std::cout << fragmentShaderID << std::endl;
std::cout << programID << std::endl;
}void sendDataToOpenGL()
{
GLfloat verts =
{
+0.0f, +0.0f, // 0
+1.0f, +0.0f, +0.0f,
+1.0f, +1.0f, // 1
+1.0f, +0.0f, +0.0f,
-1.0f, +1.0f, // 2
+1.0f, +0.0f, +0.0f,
-1.0f, -1.0f, // 3
+1.0f, +0.0f, +0.0f,
+1.0f, -1.0f, // 4
+1.0f, +0.0f, +0.0f,
};GLuint vertexBufferID;
glGenBuffers(1, &vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (char*)(sizeof(float) * 2));GLushort indices = { 0,1,2, 0,3,4 };
GLuint indexBufferID;
glGenBuffers(1, &indexBufferID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);}