We have the following code trying to draw many polygon. The point data is stored xyxyxy…
glGenVertexArrays(1, &vao); // Create the container for all vbo objects
glBindVertexArray(vao);
// push points up to graphics card as two separate vbo for x and y
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, numPoints * (2 * sizeof(float)),
bml->getPoints(), GL_STATIC_DRAW);
// Describe how information is received in shaders
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); //xy into shader
// Create a buffer object for indices of lines
uint32_t numSegments = bml->getNumSegments();
constexpr uint32_t endIndex = 0xFFFFFFFF;
const uint32_t numIndices = numPoints + numSegments;
uint32_t* lineIndices = new uint32_t[numIndices];
for (uint32_t i = 0, j = 0, c = 0; i < numSegments; i++) {
for (uint32_t k = 0; k < bml->getSegment(i).numPoints; k++)
lineIndices[c++] = j++;
lineIndices[c++] = endIndex;
}
// lineIndices = 0 1 2 3 ... 19 0xFFFFFFFF 20 21 22... 0xFFFFFFFF ....
glGenBuffers(1, &lbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, lbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * numIndices,
lineIndices, GL_STATIC_DRAW);
I am a rank beginner on shaders, so the first question is whether this shader correctly matches the code. There is no matching input for the indices but indices do not seem to be used in the vertex shader
#version 330 core
layout (location = 0) in vec3 aPos; // the position variable has attribute position 0
uniform mat4 projection;
uniform vec4 solidColor;
out vec4 ourColor; // output a color to the fragment shader
//Add a uniform bool to check if to use vertColor or Solid color
void main() {
gl_Position = projection*vec4(aPos, 1.0);
ourColor = solidColor; // set ourColor to the input color we got from the vertex data
}
Second question, when nothing shows on the screen debugging is hard. Is there any way to use old immediate mode commands to display, to test out the projection? How would I unspecify the shader, or specify a default shader so I can just test the matrix by itself. Something like:
glBegin(GL_QUADS);
glColor3f(1, 0, 0); // red
glVertex2f(0, 0);
glVertex2f(200, 0);
glVertex2f(200, 200);
glVertex2f(0, 200);
glEnd();