I am trying to create a grid using GLAD instead of GLEW. The following is part of my conversion attempt. It doesn’t draw anything on the screen yet. May I have some help please? It’s pretty standard stuff.
int indices[30] = {0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0 };
glGenVertexArrays(1, &VA01);
glBindVertexArray(VA01);
//START WORLD
// This will identify our vertex buffer
GLuint vertexbufferLAND;
// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbufferLAND);
// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbufferLAND);
// 4 x 4 x 3
GLfloat polygonVertices[48] = {};
make_plane(4,4, polygonVertices, indices);
// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(polygonVertices), polygonVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
glfwSetKeyCallback(window, key_callback);
while (!glfwWindowShouldClose(window))
{
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glm::mat4 modelMatrix = { {1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1} };
glm::mat4 view = { {1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1} };
glm::mat4 projection = { {1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1} };
ourShader.use();
GLuint MatrixID = glGetUniformLocation(ourShader.ID, "modelMatrix");
//glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &modelMatrix[0][0]);
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, glm::value_ptr(modelMatrix));
unsigned int transformLoc2 = glGetUniformLocation(ourShader.ID, "view");
glUniformMatrix4fv(transformLoc2, 1, GL_FALSE, glm::value_ptr(view));
//projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, -10000.0f);
ourShader.setMat4("projection", projection);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glBindBuffer(GL_ARRAY_BUFFER, vertexbufferLAND);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawElements(GL_TRIANGLE_STRIP, 30, GL_UNSIGNED_INT, indices );
// Swap front and back buffers
glfwSwapBuffers(window);
// Poll for and process events
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void make_plane(int rows, int columns, GLfloat *vertices, int *indices) {
// Set up vertices
for (int r = 0; r < rows; ++r) {
for (int c = 0; c < columns; ++c) {
int index = r * columns + c;
vertices[3 * index + 0] = (float)c * 20;
vertices[3 * index + 1] = (float)r * 20;
vertices[3 * index + 2] = 0.0f;
}
}
// Set up indices
int i = 0;
for (int r = 0; r < rows - 1; ++r) {
indices[i++] = r * columns;
for (int c = 0; c < columns; ++c) {
indices[i++] = r * columns + c;
indices[i++] = (r + 1) * columns + c;
}
indices[i++] = (r + 1) * columns + (columns - 1);
}
}
Thank you,
Joshua