The shaders I’ve done shades the entire screen in red instead of shading only the quad I’m drawing. The way I’ve done things in my code is described here.
#version 140 core
// vertex shader
in vec3 position;
out vec3 color;
void main(void)
{
gl_Position = vec4(position,1.0);
color = vec3(1.0,0.0,0.0);
}
#version 140 core
// fragment shader
in vec3 color;
out vec4 outColor;
void main(void)
{
outColor = vec4(color,0.1);
}
then the order in which I do the vao vbo are
/// vao buffer
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);
/// vbo - for vertices
glGenBuffers(1,&vbo1);
glBindBuffer(GL_ARRAY_BUFFER, ... );
glBufferData(GL_ARRAY_BUFFER, ...);
glVertexAttribPointer(0, 3, GL_FLOAT, ... );
glEnableVertexAttribArray(0);
glBindBuffer(0);
/// vbo for indices
glGenBuffers(1,&vbo2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ... );
glBufferData(GL_ELEMENT_ARRAY_BUFFER, ...);
glVertexAttribPointer(1, 0, GL_UNSIGNED_INT);
glEnableVertexAttribArray(1);
glBindBuffer(0);
the shader programs are compiled, and then bound with the vertex location using
glBindAttribLocation(progID, 0, "position");
I suppose the “position” is same as the variable name in vertex shader and it is bound to the 0th location as the vertices of the polygon are at 0th location in the VAO Buffer. What should I to resolve the problem here?
These are the values of vertices I’m using
float Vertices[] = { -5.0f, 5.0f, 0.0f, -5.0f, -5.0f, 0.0f, 5.0f, -5.0f, 0.0f, 5.0f, 5.0f, 0.0f };
I rotate the quad using
glRotate
function before I render, If I dont enable shader I can see the quad rotating about Y axis. If I enabled shader, the entire screen is red