Reputation: 13
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?
Upvotes: 1
Views: 711
Reputation: 48196
The drawing area is -1,-1
to 1,1
so if the quad is larger than that the entire screen is drawn.
To account for the matrix stack (input or the glRotate and friends) you need to multiply the position with gl_ModelViewMatrix
in the vertex shader. However this is not available in 140 core so you either need compatibility or maintain and pass the matrix explicitly.
Upvotes: 1