Hello everyone,
after some hours of trying to fix it, i come to the conclusion, that i have no clue what causes the problem.
The situation:
Setup: OpenGL + C++
GraphicsCard: NVIDIA GTX1060 6GB, Vendor: NVIDIA , version: 3.3.0 NVIDIA 398.82
Libaries: GLFW3, glm, glad
I have a main class that calls the draw function of my chunk class. The chunk class currently has 20 vertices defined, and a set of 4 form a plane. To draw the planes i use an index buffer with DrawElements.
And everything works fine for the first 16 vertices, but when i add another 4 vertices to the vertex buffer, the triangles of the corresponding 4 vertices do not get drawn.
If i switch the order in which i push the vertices into the vertex buffer, then the triangles do get rendered, but again the last 4 pushed do not.
(and yes i do know that i could reduce the amount of vertices, because of the index buffer, but for practise reason i wanan use them in that way atm. but the vertex and index buffer should be able to handle way more vertices)
But the indexbuffer is working fine, meaning, i can draw more triangles between the first 16 vertices.
The code of the chunk class:
#include "chunk.h"
chunk::chunk(float Seed, float Size, std::vector<float> Heightmap, float XPosition, float ZPosition, float HighestHeightValue, float LowestHeightValue){
seed = Seed;
size = Size;
heightmap = Heightmap;
xPosition = XPosition;
zPosition = ZPosition;
highestHeightValue = HighestHeightValue;
lowestHeightValue = LowestHeightValue;
//generateVertices();
vertices.push_back({ 0.0, 1.0, 0.0, 0.0 });
vertices.push_back({ 0.0, 0.0, 0.0, 0.0 });
vertices.push_back({ 1.0, 1.0, 0.0, 0.0 });
vertices.push_back({ 1.0, 0.0, 0.0, 0.0 });
vertices.push_back({ 0.0, 1.0, -1.0, 0.0 });
vertices.push_back({ 0.0, 0.0, -1.0, 0.0 });
vertices.push_back({ 1.0, 1.0, -1.0, 0.0 });
vertices.push_back({ 1.0, 0.0, -1.0, 0.0 });
vertices.push_back({ 1.0, 1.0, 0.0, 0.0 });
vertices.push_back({ 1.0, 1.0, -1.0, 0.0 });
vertices.push_back({ 1.0, 0.0, 0.0, 0.0 });
vertices.push_back({ 1.0, 0.0, -1.0, 0.0 });
vertices.push_back({ 0.0, 1.0, 0.0, 0.0 });
vertices.push_back({ 0.0, 1.0, -1.0, 0.0 });
vertices.push_back({ 0.0, 0.0, 0.0, 0.0 });
vertices.push_back({ 0.0, 0.0, -1.0, 0.0 });
vertices.push_back({ 0.0, 1.0, 1.0, 0.0 });
vertices.push_back({ 0.0, 0.0, 1.0, 0.0 });
vertices.push_back({ 1.0, 1.0, 1.0, 0.0 });
vertices.push_back({ 1.0, 0.0, 1.0, 0.0 });
indices.push_back(0);
indices.push_back(2);
indices.push_back(1);
indices.push_back(1);
indices.push_back(2);
indices.push_back(3);
indices.push_back(4);
indices.push_back(5);
indices.push_back(6);
indices.push_back(6);
indices.push_back(5);
indices.push_back(7);
indices.push_back(8);
indices.push_back(9);
indices.push_back(10);
indices.push_back(10);
indices.push_back(9);
indices.push_back(11);
indices.push_back(12);
indices.push_back(14);
indices.push_back(15);
indices.push_back(15);
indices.push_back(13);
indices.push_back(12);
indices.push_back(16); //these do not get rendered
indices.push_back(18);
indices.push_back(17);
indices.push_back(17);
indices.push_back(18);
indices.push_back(19);
std::cout << vertices.size();
setUpChunk();
}
chunk::~chunk()
{
}
void chunk::setUpChunk() {
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) * sizeof(vertex), &vertices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *) 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *) (3 * sizeof(float)));
glEnableVertexAttribArray(1);
glBindVertexArray(0);
}
void chunk::draw(Shader shader) {
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
}
Here is a picture of it:
[ATTACH=CONFIG]1840[/ATTACH]
Hope someone can help me =)
Greetings Luca